Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

progressbar setvisible not working

I have a layout like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" 
android:background="@drawable/menu_background"
>

<ProgressBar 
  android:id="@+id/aPBar"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerInParent="true"
  style="@android:style/Widget.ProgressBar.Inverse"/>

 ...

</RelativeLayout>

And in my onCreate method I do this to hide the ProgressBar at first:

LayoutInflater inflater = getLayoutInflater();
RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.achievements_screen, null);

progressBar=(ProgressBar)layout.findViewById(R.id.aPBar);
progressBar.setVisibility(View.INVISIBLE);

But the ProgressBar is still visible all the time ... I also tried View.GONE.

When i set

android:visible="gone"

in the XML file, the ProgressBar doesnt show up, but I can't make it appear with

 progressBar.setVisibility(View.Visible);
like image 799
yon Avatar asked Jun 24 '12 19:06

yon


People also ask

What is difference between ProgressBar and SeekBar?

What is difference between ProgressBar and SeekBar? An example of SeekBar is your device's brightness control and volume control. Important Note: Attribute of a SeekBar are same as ProgressBar and the only difference is user determine the progress by moving a slider (thumb) in SeekBar.

What is indeterminate ProgressBar?

ProgressBar is used to display the progress of an activity while the user is waiting. You can display an indeterminate progress (spinning wheel) or result-based progress.

Which attribute is used to display ProgressBar horizontally?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.

What is the use of ProgressBar?

ProgressBars are used as loading indicators in android applications. These are generally used when the application is loading the data from the server or database. There are different types of progress bars used within the android application as loading indicators.


1 Answers

You are inflating a new view using the Layout Inflater. This is NOT the view currently on the screen.

Therefore changing it's visibility won't affect the screen UI.

Further up your Activity you must have called setContentView and this is the layout that is visible on your UI.

Therefore calling:

findViewById will return your progress bar on the screen, but calling layout.findViewById will return that layouts progress bar (correctly) but that is not the progressBar you can see on your screen.

like image 72
Blundell Avatar answered Sep 23 '22 07:09

Blundell