我有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