我有FragmentTransaction的問題。我的項目使用FragmentTabhost,其中一個選項卡是Profile選項卡。 當配置文件選項卡是選擇我加載配置文件片段。然後按Edit按鈕,替換爲EditProfile。 代碼在Profile.javaonActivityResult不能在使用FragmentTransaction的片段中工作
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();
}
}
在代碼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));
}
}
}
在EditProfile片段,我有一個按鈕,一個ImageView的化身。當按下按鈕時,我想要在ImageView中顯示garlary的圖片。這個問題是當我從配置文件選項卡加載EditProfile選擇它運行良好,但我從配置文件片段onActivityResult轉移不運行。
你能幫我嗎?
onActivityResult在其中調用片段的主要活動將收回數據..從那裏您必須將結果傳遞到所需的片段 – Meenal 2014-11-02 05:16:20