在我的列表视图没有填充数据库数据时,有什么更好的方法来显示进度指示器?
我找到了一些使用assynctask的方法,但在我的例子中,我使用的是Loader / CursorLoader.
public class TestActivity extends SherlockFragmentActivity implements LoaderCallbacks<Cursor> { SimpleCursorAdapter mAdapter; ListView mListView; private static final String[] UI_BINDING_FROM = new String[] { TestDBAdapter.KEY_NAME,TestDBAdapter.KEY_ICON }; private static final int[] UI_BINDING_TO = new int[] { R.id.text,R.id.icon }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_Test); mListView = (ListView) findViewById(R.id.listview); mAdapter = new TestAdapter(getApplicationContext(),R.layout.list_item_Test,null,UI_BINDING_FROM,UI_BINDING_TO,0); mListView.setAdapter(mAdapter); getSupportLoaderManager().initLoader(0,this); } @Override public Loader<Cursor> onCreateLoader(int id,Bundle args) { Uri uri = ContentProviderTest.CONTENT_URI; CursorLoader cursorLoader = new CursorLoader( this,uri,null); return cursorLoader; } @Override public void onLoadFinished(Loader<Cursor> loader,Cursor data) { mAdapter.swapCursor(data); } @Override public void onLoaderReset(Loader<Cursor> loader) { mAdapter.swapCursor(null); } }
一个可能的解决方案是创建一个扩展ListFragment的新类并使用setListShown()方法,但我不知道它是否是解决此问题的最佳方法.
谢谢