0
携帯電話から画像を選択する際にコードが正常に機能していますが、アップロードする前にプレビューが表示されません。どうしましたか?モバイルストレージ(Androidスタジオ)から選択した画像を表示できません
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private static final int PIC_ID = 1;
Button uButton, dButton;
EditText firstText, secondText;
ImageView firstImage, secondImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uButton = (Button)findViewById(R.id.uButton);
dButton = (Button)findViewById(R.id.dButton);
firstText = (EditText)findViewById(R.id.firstText);
secondText = (EditText)findViewById(R.id.secondText);
firstImage = (ImageView)findViewById(R.id.firtsImage);
secondImage = (ImageView)findViewById(R.id.secondImage);
firstImage.setOnClickListener(this);
uButton.setOnClickListener(this);
dButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.firtsImage:
Intent imageIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(imageIntent, PIC_ID);
break;
case R.id.dButton:
break;
case R.id.uButton:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PIC_ID && resultCode == RESULT_OK && data != null){
Uri selected = data.getData();
firstImage.setImageURI(selected);
}
}
と私のactivity_main.xmlファイル私は頭痛が何も見つからなかっ得たまで、私はそれをGoogleで検索しました
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/firtsImage"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="@+id/firstText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/uButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Upload"/>
<ImageView
android:id="@+id/secondImage"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="@+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/dButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="download"/>
です。
が働いて、あなたに非常に多くの仲間をありがとうございました! – mogogogo