Russ Wheeler
Russ Wheeler

Reputation: 2630

Android - Can't hide progress bar

So I've checked the other questions to hide a progress bar but all seem to suggest doing what I'm already doing.

I'm trying to use

mProductListProgressBar.setVisibility(View.GONE);

and I'm finding it by

mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);

I know it's the correct progress bar as I can move it around the screen before with various LayoutParams commands. But it won't hide.

The current code I have (including the moving of the progress bar) is

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);

mProductListProgressBar.setVisibility(View.GONE);
mProductListErrorTextView.setVisibility(View.VISIBLE);
mProductListErrorTextView.setText(errorMessage);

The progress bar moves to left and bottom but is still visible. I have tried View.INVISIBLE as well as View.GONE but neither work.

It's driving me nuts!

Thanks

UPDATE 1

protected void showError(int errorMessage){

    /*RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    mProductListProgressBar.setLayoutParams(params);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mProductListProgressBar.setLayoutParams(params);
    */
    mProductListProgressBar.setVisibility(View.GONE);
    mProductListErrorTextView.setVisibility(View.VISIBLE);
    mProductListErrorTextView.setText(errorMessage);
}

and calling it with

showError(R.string.wish_list_empty);

UPDATE 2

xml of fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <GridView
        android:id="@+id/product_list_gridview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:horizontalSpacing="@dimen/standardMargin"
        android:listSelector="@android:color/transparent"
        android:numColumns="@integer/columns"
        android:scrollbarStyle="outsideOverlay"
        android:verticalSpacing="@dimen/standardMargin" />

    <RelativeLayout
        android:id="@+id/product_list_header"
        android:layout_width="match_parent"
        android:layout_height="@dimen/refineHeaderHeight"
        android:background="@drawable/product_list_header"
        android:visibility="gone" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:padding="10dp"
            android:src="@drawable/dropdown_image" />

        <TextView
            android:id="@+id/product_list_header_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center|left"
            android:paddingLeft="10dp"
            android:textAllCaps="true"
            android:textColor="@android:color/black"
            android:textIsSelectable="false"
            android:textSize="@dimen/standardTextSize" />

        <TextView
            android:id="@+id/product_list_refine_button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/button"
            android:clickable="true"
            android:gravity="center_vertical"
            android:paddingLeft="20dp"
            android:paddingRight="30dp"
            android:text="@string/refine"
            android:textAllCaps="true"
            android:textColor="#838383"
            android:textSize="@dimen/standardTextSize" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/product_list_footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        android:background="@drawable/product_list_footer"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="15dp"
        android:visibility="gone" >

        <ProgressBar
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_gravity="center"
            android:layout_marginRight="10dp"
            android:background="@android:color/transparent"
            android:gravity="center" />

        <TextView
            android:id="@+id/product_list_footer_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/loading_message"
            android:textAllCaps="true"
            android:textSize="@dimen/standardTextSize" />
    </LinearLayout>

    <ProgressBar
        android:id="@+id/product_list_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"/>

    <TextView
        android:id="@+id/product_list_error_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textAllCaps="true"
        android:textSize="@dimen/standardTextSize"
        android:visibility="gone" />

    <TextView
        android:id="@+id/debug"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#aa000000"
        android:gravity="left|center_vertical"
        android:minLines="2"
        android:padding="10dp"
        android:textColor="@android:color/white"
        android:visibility="gone" />

</RelativeLayout>

Upvotes: 3

Views: 6792

Answers (4)

kip2
kip2

Reputation: 6863

A solution that worked for me was to hide the view in XML:

android:visibility="gone"

and then unhide/hide it at runtime when needed:

yourProgressBar.setVisibility(View.VISIBLE) // or View.VISIBLE depending on situation

Upvotes: 1

EdgarK
EdgarK

Reputation: 890

I know that it is an old question. But I just spent a lot of time debugging similar situation. I could not hide ProgressBar on top of unityPlayer view.

One more thing to ensure is that You are hiding it while in UI thread.

To ensure surround Your UI code with:

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            loadingIndicator.setVisibility(View.GONE);
        }
    });

Upvotes: 1

kiruwka
kiruwka

Reputation: 9450

The problem with this behaviour usually happens when your view which you try to hide is needed / referenced by someone else.

In your case, as you mentioned in the comments, you use mProductListProgressBar for setEmptyView() of your GridView.

Another possibility of running into similar troubles when there other views in your relative container layout which set their position relatively to your mProductListProgressBar. This setting could be either in the code or in .xml.

Please make sure you don't have any of above and View.GONE should work fine.

As for setEmptyView() - it is only used to show something meaningful to the user when your adapter is empty. I recommend just setting up simple Layout for that with, say, TextView "no items", in the middle, and pass it to setEmptyView()

Hope that helps.

Upvotes: 2

Dinesh Prajapati
Dinesh Prajapati

Reputation: 9510

I don't know how your code is written but had similar problem and resolved by removing the view object from declaration

like

mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);

should be

mProductListProgressBar = (ProgressBar) findViewById(R.id.product_list_progressbar);

Try it and check

Reason is the progress bar is on the top of every view in the hierarchy and it's not belong to any root view.

Upvotes: 0

Related Questions