I have a view with EditText
, Button
and ListView
.
Button's onClick()
parses some site (this part works OK), but it takes some time to display the parsed info in ListView
, so I want to display small ProgressBar
on the place, where the ListView
should take place after a while.
So, I add this to my layout (I write important part here):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout1"
android:weightSum="1.0">
<EditText
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".86" />
<ImageButton
android:layout_height="match_parent"
android:layout_width="0px"
android:layout_weight=".14" />
</LinearLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@id/layout1"
android:gravity="center"
android:layout_centerInParent="true"
android:id="@+id/progressbar" >
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="@android:style/Widget.ProgressBar.Small" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layout1">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
In source code:
progressBar = (RelativeLayout) findViewById(R.id.progressbar);
And everytime I want to show the ProgressBar
, I do this:
progressBar.setVisibility(View.VISIBLE);
for disabling:
progressBar.setVisibility(View.INVISIBLE);
But this doesn't work.
How can I work this out?
Android ProgressBar with Determinate Mode Generally, we use the Determinate progress mode in progress bar when we want to show the quantity of progress has occurred. For example, the percentage of file downloaded, number of records inserted into a database, etc.
Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.
Progress bar supports two modes to represent progress: determinate, and indeterminate.
There's no need to manipulate your ProgressBar
's visibility. ListView
has a feature called "empty view" which is shown only if your ListView
is empty. Here's what you need to do to use it:
ListActivity
, use
android:id="@android:id/list"
for your ListView
and
android:id="@android:id/empty"
for your ProgressBar
.ListActivity
, there's a setEmptyView()
method of your ListView
, which lets you do the same thing.The above method fits best if you don't need to empty your ListView
(e.g. data is loaded only once, at the activity startup). If you need to set data after that, it is better to use ViewSwitcher
, which also has great advantage - it lets you apply transition animation. For details on ViewSwitcher
, take a look at this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With