I have MainActivity which extends SherlockListActivity. Here is onCreate method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new MyXMLDownloader().execute(this);
}
MyXMLDownloader is just AsyncTask class, which I use to download XML file from http. In onPostExecute method I’m calling makeMainGUI() which creates GUI based on that XML file (I mean it fills my ListView).
Here is main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
I would like to add ProgressBar widget (and some text). It should be shown before downloading XML and it should disappear after ListView is filled (of course it happens after XML is downloaded). How can I achieve that?
I have problem with that, because I must have ListView in main.xml, because I MainActivity class extends SherlockListActivity.
EDIT:
I managed to do something like this:
<ProgressBar
android:id="@android:id/empty"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
I added ProgressBar to main.xml with “empty” id. It is shown as long as ListView is empty, which is correct. But I don’t know how can I place a TextView here too because only one item can have an “empty” id.
EDIT2:
As I think I managed to do this. In main.xml I added following:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@android:id/empty">
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/progressBar1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Please wait"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/waitingTextView"/>
</LinearLayout>
And it is something I needed. Thank you!
In the AsyncTask class use onPrexecute method to display progress dialog and use onPostExecute to dismiss it:
Don’t forget to define pDialog before you call it: