我有捆绑对象的问题。当我通过数据(onCLick按钮)从活动到片段我得到了捆绑对象的值,并在我将值传递给适配器后...我有问题:捆绑对象再次从活动中获取值(但现在值为空),并通过空值到适配器...我不知道为什么第一次束之后,从活动得到再次值...我希望你能帮助我捆绑对象问题
我告诉我的玩具代码
活动:
Bundle bundle = new Bundle();
bundle.putIntegerArrayList("oki", hm);
bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze);
System.out.println("PERO:" + bundle);
/*
MyListFragment2 myFragment = new MyListFragment2();
myFragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.pero, myFragment);
transaction.commit();*/
MyListFragment myFragment = new MyListFragment();
myFragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.a, myFragment);
transaction.commit();
片断:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("BUNDLES1 prima:" + bundle);
bundle = getArguments();
System.out.println("BUNDLES1 dopo:" + bundle);
if (bundle != null) {
strtext2 = bundle.getIntegerArrayList("oki");
quantitàpizze2=bundle.getIntegerArrayList("okiquantitapizze");
System.out.println("CAZZ2:" + strtext2);
System.out.println("PRESO2:" + quantitàpizze2);
}
}
你可以粘贴你的整个活动?还有,当包再次通过时,你正在做什么?你是否正在旋转你的屏幕,来自另一个应用程序等? –
不,当我点击按钮之前传递数据正确的方式,并在重新计算数据.....所以片段创建两次.... – androidiano
任何消息呢? –