我在更改Actionbar Tab片段的方向时遇到错误。我读了关于android中的状态管理的帖子。
我得到了使用onSaveInstanceState(Bundle savedInstanceState)
但在我的情况onTabUnselected
事件中,我收到了碎片对象的错误
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
System.out.println("1::");
Fragment fragment = adapter.getItem(tab.getPosition());
System.out.println("2::"+fragment);<--- shows long id
**line 112 -->if (fragment instanceof InfoFragment) { <--- error at this line Null** pointer excp
((InfoFragment) fragment).setData();
}else if (fragment instanceof PortFragment) {
((PortFragment) fragment).setData();
}
}
如何通过致电onSaveInstanceState
解决问题?
// Set data to objects
public void setData() {
List<String> sales = new ArrayList<String>();
sales.add(0, String.valueOf(customerId));
sales.add(1, String.valueOf(prospectId));
sales.add(2, String.valueOf(commodityId));
sales.add(3, txtAESplNt.getText().toString());
sales.add(4, Constants.Common.AIR_LOB);
//set data to global class
mainActivity.setSalesInfoData(sales);
}