ListView在旋转时消失

时间:2013-06-26 14:29:59

标签: android android-layout android-listview android-fragments

片段 onCreateView 方法

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.myCustomFragmentLayout, null);

        MyFragmentClass.myListView = (ListView)view.findViewById(R.id.list);
        MyFragmentClass.counter = (TextView)view.findViewById(R.id.counter);

        return view;
}

片段 onStart 方法

public void onStart() {
        super.onStart();

        Builder builder;
        try {
            builder = new Builder();

            MyAsyncTask task = new MyAsyncTask (this, builder);
            task.execute();

        } catch (MyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

异步 onTaskFinished 方法

public void onTaskFinished(BuilderResult result) {
        // check if ListAdapter instance was ever created
        if(null == MyFragmentClass.listAdapter) {
            MyFragmentClass.listAdapter = new MyListAdapter(MyApplication.getContext(), (ArrayList<ListItem>)result.getList());
            MyFragmentClass.myListView.setAdapter(MyFragmentClass.listAdapter);         
        } else {
            MyFragmentClass.listAdapter.clear();
            MyFragmentClass.listAdapter.addCalls((ArrayList<ListItem>)result.getList());
        }

        MyFragmentClass.counter.setText(String.valueOf(result.getTotalCounter()));      

        // dismiss progress dialog
        MyFragmentClass.progressDialog.dismiss();
        MyFragmentClass.progressDialog = null;
}

由于Fragment对象转换,我必须有静态窗口小部件对象。

问题: ListView轮换变化消失了。不知道为什么在重新创建活动后ListView不可见。

EDITED

投射并执行基础片段对象的过滤方法。

public void onDialogPositiveClick(DialogFragment dialog) {

        for(int i = 0; i < mTabsAdapter.getCount(); i++) {
            Fragment fragment = mTabsAdapter.getItem(i);

            if(fragment instanceof BaseOmoFragment) {
                ((BaseOmoFragment) fragment).filter();
            }
        }
}

P.S。我应该提一下,我使用ActionBarSherlock库。

0 个答案:

没有答案