I've been adding a ProgressBar
to the fragments in my app. I've set it up to the two main fragments (used as tabs) as follows:
ProgressBar
in activity_main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Setting ProgressBar
VISIBLE
and GONE
:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
This works without any problems. I've tried to add another ProgressBar
to another fragment which has a WebView
:
ProgressBar
in fragment_article.xml
:
<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"
tools:context="info.androidhive.slidingmenu.ArticleFragment$PlaceholderFragment" >
<WebView android:id="@+id/webPage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Setting Visibility:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
Setting the visibility the same way as the previous code but for some reason this is not setting the ProgressBar
to GONE
. Not sure what's wrong.
I've tried using clearAnimation
as suggested here Android, setVisbility to gone not working in RelativeLayout but still nothing.
spinner.clearAnimation();
spinner.setVisibility(View.GONE);
I had a same issue (progressBar.setVisibility() was not working).
As @Illegal Argument said,
// in Activity
ProgressBar mProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
mProgressBar.setVisibility(View.GONE);
should be working, if that code runs on uiThread(mainThread).
My problem was that I was trying to run the code not on uiThread. So I solved the issue by changing code from
mProgressBar.setVisibility(View.GONE);
to
runOnUiThread(new Runnable() {
@Override
public void run() {
mProgressBar.setVisibility(View.GONE);
}
});
Check this code:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
If you are using fragments it should be like this:
spinner = (ProgressBar)viewIinflated.findViewById(R.id.progressBar1);//same case with dialogs
If you are using activity then:
spinner = (ProgressBar)findViewById(R.id.progressBar1);
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