嗨我有一个带有textview的fragmentA。当我点击它时,我去了fragmentB,它有一个项目列表。 当点击listitem时,iam返回fragmentA并使用listitem值更新textview。 现在再次当iam点击textview时它抛出 Illegalstateexception:无法更改片段的标签
boreselect.setOnClickListener(new OnClickListener() {
Fragment newContentbore = new BoreValuesListFragment();
@Override
public void onClick(View v) {
Fragment currentFragment = getFragmentManager().findFragmentByTag(FragmentChangeActivity.mFragmentStack.peek());
String tagbore = newContentbore.toString();
FragmentChangeActivity.mFragmentStack.add(tagbore);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.content_frame, newContentbore,tagbore);
transaction.hide(currentFragment);
transaction.addToBackStack(tagbore);
transaction.commit();
}
});
我的堆栈跟踪
01-20 00:14:59.819: E/AndroidRuntime(26655): FATAL EXCEPTION: main
01-20 00:14:59.819: E/AndroidRuntime(26655): java.lang.IllegalStateException: Can't change tag of fragment BoreValuesListFragment{42a283a0 #2 id=0x7f090044 BoreValuesListFragment{42a283a0}}: was BoreValuesListFragment{42a283a0} now BoreValuesListFragment{42a283a0 #2 id=0x7f090044 BoreValuesListFragment{42a283a0}}
01-20 00:14:59.819: E/AndroidRuntime(26655): at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:351)
01-20 00:14:59.819: E/AndroidRuntime(26655): at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:342)
答案 0 :(得分:0)
这可能是因为你要添加相同的片段实例三 时间到列表。您应该为每个页面创建一个新实例。