I have problem with FragmentTransaction. My project use FragmentTabhost and one of tabs is Profile tab. When Profile tab was choice I load Profile fragment. then I press Edit button, replace to EditProfile. code in Profile.java
public class Profile extends Fragment implements OnClickListener{
........
public void onClick(View v) {
EditProfile profile = new EditProfile();
Bundle bundle=new Bundle();
bundle.putString("Token", tokenId);
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.container_framelayout, fragment);
transaction.commit();
}
}
In code EditProfile.java
public class Editprofile extends Fragment implements OnClickListener{
.........
public void onClick(View v) {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent,SELECT_PICTURE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode==SELECT_PICTURE && data!=null)
{
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
avatar.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
in EditProfile Fragment, I have one button and one ImageView avatar. when button was pressed, I want get picture of garlary to show at ImageView. This problem is when I load EditProfile from Profile tab was chosen it run well, but I transfer from Profile Fragment onActivityResult not run.
Can you help me?