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