我的布局有点复杂:
我有一个垂直的viewflipper,在第二页上有一个包含多个片段的水平viewpager。 在第三页上,我有一个带有textfild的listview,它可以根据片段中togglebuttons的状态过滤listview。
由于这一事实,由于性能原因,viewflipper有一些缓存和卸载机制,我不得不对片段中的togglebuttons进行静态引用:
public class FragmentOne extends Fragment {
public static ToggleButton btn_1;
public static ToggleButton btn_2;
...
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
btn_1 = (ToggleButton)V.findViewById(R.id.btn_1);
btn_2 = (ToggleButton)V.findViewById(R.id.btn_2);
...
}
}
一切正常,但由于某些原因,仅在平板电脑上(manly Galxy Tab3),当我想检查Togglebuttons的状态时,我得到一个nullpointerexception:
filterListview(){
if(FragmentOne.btn_1.isChecked()){ //doSomething };
....
}
任何想法会导致什么问题? (顺便说一句,我没有平板电脑的任何特定布局,只有一个应用程序布局,而且应用程序始终以纵向模式运行)