片段 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库。