我想在加载列表之前显示进度条,如下图所示。我的班级使用 AsyncTask 扩展了 SherlockListFragment。我看了很多,但没有得到合适的信息来实施 progressbar 。任何人都可以帮助我如何实现如下图所示的进度条。
提前致谢。
图 1
以下是我的课
public class Residential extends SherlockListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle saved) {
View view = inflater.inflate(R.layout.residential_list,container, false);
resListviewId = (ListView)view.findViewById(android.R.id.list);
projectList = new ArrayList<HashMap<String,String>>();
new LoadProjects().execute();
return view;
}
public void onStart() {
super.onStart();
}
//inner class for network operation
private class LoadProjects extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
return null;
}
@Override
protected void onPostExecute(String result) {
ListAdapter projAdapter = new SimpleAdapter(getSherlockActivity(),
projectList, R.layout.residential_list_item,
new String[] {PROJ_ID,PROJ_NAME}, new int[]
{R.id.projectId,R.id.projectName});
//updating the UI
setListAdapter(projAdapter);
}
}
}
以下是progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/projectLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:padding="10dp"
android:visibility="gone">
<ProgressBar
android:id="@+id/projectprogressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/projectProgressTxtvw"
android:text="@string/Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>