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
It's probably due the fact that View.GONE
will prevent the View
from being drawn to the screen, while another View
android:layout_align[POSITION]
component may be defined to that View
, so their position can't be calculated.
View.INVISIBLE
will work cause it just make it invisible, but the View
is still there and other View
can calculate their position if the align is set to it
This work for me:
rootView.findViewById(R.id.progress_bar).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);
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);
}
});
progressBar.setVisibility(ProgressBar.VISIBLE);