How to get image from gallary to set in Imageview in fragment ? onActivityResult not called in fragment..this the code i wrote in fragment
img_user.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContext().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
img_user.setImageBitmap(BitmapFactory.decodeFile(picturePath));
cursor.close`enter code here`();
} else {
Toast.makeText(getActivity(), "Try Again!!", Toast.LENGTH_SHORT)
.show();
}
}