Nachdem ich auf die Schaltfläche geklickt und ein Bild ausgewählt habe, konnte ich auf meine Android-Galerie zugreifen, aber in der Bildansicht wird nichts angezeigt.
hier ist die main.xml:
Code: Select all
hier ist mein Java-Code:< /h2>
Code: Select all
public class ImagesProj extends Activity {
// define the variable that will show the gallery images
ImageView imageViewGallery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.images_proj);
// connect the variable to the images_proj.xml
imageViewGallery = (ImageView) findViewById(R.id.imageViewGallery);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
// This function is called after clicking the Browse From Gallery button
public boolean onButtonClicked(View view) {
// access the images gallery
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 2);
return true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
// String picturePath contains the path of selected Image
// Show the Selected Image on ImageView
ImageView imageView = (ImageView) findViewById(R.id.imageViewGallery);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
Der Beitrag, den ich mir angesehen habe:Wählen Sie ein Foto aus der Galerie aus und zeigen Sie es in einer Bildansicht