当我将页面从此页面刷到另一页时,我将viewpager应用于此页面我得到了例外:
异常是“指定的孩子已经有父母。你必须打电话 孩子的父母首先
removeView()
“
我如何解决这个问题任何人都可以告诉我这是我的错误控制台代码。
public class FamilyCosts extends Fragment
{
TextView user_one,user_two,user_three;
FragmentManager fManager;
FragmentTransaction tx;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
final View v=inflater.inflate(R.layout.activity_familycosts,container,false);
fManager=getActivity().getFragmentManager();
user_one=(TextView)v.findViewById(R.id.user_one);
user_two=(TextView)v.findViewById(R.id.user_two);
user_three=(TextView)v.findViewById(R.id.user_three);
user_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tx=fManager.beginTransaction();
tx.replace(R.id.fragment, new Jeff());
tx.commit();
}
});
user_two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tx=fManager.beginTransaction();
tx.replace(R.id.fragment, new Harriet());
tx.commit();
}
});
user_three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tx=fManager.beginTransaction();
tx.replace(R.id.fragment, new George());
/*tx.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
tx.addToBackStack(null);*/
tx.commit();
}
});
return v; }}