0

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?

thanh duc
  • 189
  • 2
  • 8
  • onActivityresult of main activity in which fragment is called will recived the data..from there you have to pass the result to the desired fragment – Meenal Nov 02 '14 at 05:16

1 Answers1

0

It seems this issue was fixed with Android Support Library 23.2+.

More details: Info1 and Info2

The simple solution is to use Android Support Library revision 23.2.1 or above.

Community
  • 1
  • 1
ReVs
  • 57
  • 5