0

片段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重新创建活动后不可见。

已编辑

转换和执行基本片段对象的过滤方法。

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();
            }
        }
}

PS 我应该提到我使用ActionBarSherlock库。

4

0 回答 0