AXSM
AXSM

Reputation: 1182

View visibility do not shows after being invisible

I have two views one is a button and the other is LinearLayout.

When i set View.GONE and then to View.VISIBLE the view wont get visible again.
This mechanism was working in the past.

android:id="@+id/selector_controls"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/shape_round_white_1"/>

<include
    android:id="@+id/actions_container"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    layout="@layout/wait_request_accept_panel"
    android:visibility="visible"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true" />


<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@id/selector_controls"
    android:layout_alignEnd="@id/selector_controls"
    android:layout_alignLeft="@id/selector_controls">

Now... what i want is to toggle is the elements inside wait_request_accept_panel this is the layout file, I want to toggle elements inside it..

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

<RelativeLayout
    android:id="@+id/wait_container"
    android:visibility="invisible"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@drawable/shape_round_white_1">

    <!-- Other view elements -->

</RelativeLayout>


<Button
    android:id="@+id/btnAccept"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    style="@style/H18b"
    android:visibility="visible"
    android:background="@drawable/shape_round_white_1"
    android:text="@string/str_accept"
    android:layout_alignParentTop="true"/>
   </RelativeLayout>

As you can se here there is two elements basically a wait_container which shows up when user is waiting, and a Button btnAccept it only change state once: one in the original state which is, wait_container is GONE and button Button which is visible at first time. When I hit btnAcceptthe btn changes to GONE and the wait container changes to VISIBLE Here is the programatic impementation:

switch (req.getType()) {
        case REQ: // this is the initial flow
            waitContainer.setVisibility(View.GONE);
            acceptBtn.setVisibility(View.VISIBLE);
            break;
        case ACCEPT: // after hit the accept btn it toggles the two views
            acceptBtn.setVisibility(View.GONE);
            waitContainer.setVisibility(View.VISIBLE);
            break;
    }

Init details

waitContainer = (RelativeLayout) view.findViewById(R.id.wait_container);
acceptBtn     = (Button) view.findViewById(R.id.btnAccept);
cancelBtn     = (Button) view.findViewById(R.id.btnCancel);

Something to take in count is the fact the waitContainer and acceptBtn are included, they came from another xml file, I did that because I wanted to reuse code, but in this moment that's not so important since the current screen is the only that uses the wait_request_accept_panel.xml file.

SOLUTION

The view were always there, but it's alpha channel was modified by an animation when the fragment was starting, I sent by mistake the viewContainer as a parameter to the animation method which i turns animates its alpha channel.

Upvotes: 1

Views: 76

Answers (2)

Hemant Parmar
Hemant Parmar

Reputation: 3976

Check the visibility of view after that apply ViSIBLE/GONE have look

if(waitContainer.getVisibility()== View.GONE)
    {
      waitContainer.setVisibility(View.VISIBLE);
    }else{
     waitContainer.setVisibility(View.GONE);
    }

Upvotes: 2

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75798

You can try with getVisibility ().

Returns the visibility status for this view.

 if(waitContainer.getVisibility()== View.GONE)
    {
      acceptBtn.setVisibility(View.GONE);
      waitContainer.setVisibility(View.VISIBLE);
    }

Upvotes: 2

Related Questions