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 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 ProgressBarstill showing up all the time ... I also tried View.GONE.

When i install

android:visible="gone"

in the xml file is ProgressBarnot displayed, but I cannot get it to display with

 progressBar.setVisibility(View.Visible);
+5
source share
3 answers

You inflate a new view using the Inflater layout. This is NOT the current screen view.

Therefore, a change in its visibility will not affect the screen interface.

In addition to your activity, you should have called setContentViewand this is the layout that appears in your interface.

Therefore, the call:

findViewById , layout.findViewById (), Bar, .

0

:

rootView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
0

The workaround for me was to hide the view in XML and then show / hide it at runtime when necessary: android:visibility="gone"

0
source

All Articles