现在我的问题是:
这是一个针对点击ImageButton的解决方法,它试图缓存先前的图像Uri。传递null可以有效地重置它。
private ImageButton mImageSelect;
private static final int GALLERY_REQUEST =1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
mImageSelect=(ImageButton) findViewById(R.id.imageselect);
mImageSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent= new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, GALLERY_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
if(requestCode== GALLERY_REQUEST && resultCode==RESULT_OK){
Uri selectedImageUri=data.getData();
if (null != selectedImageUri) {
mImageSelect.setImageURI(selectedImageUri);
Toast.makeText(PostActivity.this, "Image Selected", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(PostActivity.this,"Image Not Selected",Toast.LENGTH_SHORT).show();
}
}
}