我想在我的应用程序中添加ListView,在LinearLayout加载时,而不是列表有进度条.这类似于系统应用程序,您可以在其中管理您的应用程序.
我找到了一些关于它的信息,但没有一个是好的.看起来最好的一个就是创建两个布局(一个带有进度条,另一个带有ListView),然后onPreExecute()(我AsyncTask用于此)显示进度条.然后onPostExecute()隐藏它,这就是全部.
我试图实现它,但我有ScrapView错误,没有更多的信息,它是如何做到的.
所以,我的问题是,你会怎么建议我这样做?我不想要任何进度对话框.
编辑:
这是我的代码片段,显示了我到目前为止所做的事情:
TestActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylist_layout);
wordList = (ListView) findViewById(R.id.wordsList);
//...
}
private class AsyncDBDownload extends AsyncTask {
LinearLayout linlaHeaderProgress = (LinearLayout) findViewById(R.id.linlaHeaderProgress);
@Override
protected String doInBackground(String... params) {
try {
refreshList();//upload of contetn and set of adapter
} catch (Exception ex) {
Log.e(TAG, ex.toString());
}
return null;
}
@Override
protected void onPostExecute(String result) {
linlaHeaderProgress.setVisibility(View.GONE);
wordList.setVisibility(View.VISIBLE);
}
@Override
protected void onPreExecute() {
linlaHeaderProgress.setVisibility(View.VISIBLE);
}
}
private void refreshList() {
//List content download into Cursor - adapterCursor
//...
wordList.setAdapter(adapterCursor);
}
word_list.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
android:id="@+id/pbHeaderProgress"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
android:id="@+id/wordsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true" >
额外的两件事:
在onResume()那里要求执行AsyncTask;
在mylist_layout.xml应该列出的地方有包括在这个布局word_list.xml布局中的包括
其他事情:
我不想使用进度对话框,因为它不符合我的需要,我发现它看起来不适合我的目的.我想替换列表,而不是更多广告.
ListFragment似乎相当不错,但我认为可能还有其他更好或更简单的解决方案来实现我想要的东西.
我正在做Android 2.2/2.3兼容的应用程序,我忘了提,所以如果有些东西不在里面android.support.v4.app.Fragment,我将不会使用它.