L. Thane
L. Thane

Reputation: 83

Android - setVisibility not changing visibility of RelativeLayout

I am trying to manipulate the visibility of RelativeLayout on a certain click event, using the visibility attribute.

After adding event handlers to each list item, I can check that the visibility status is changing, but in the Android emulator, the screen doesn't change at all (and I have tested it with visibility="visible" in the XML to make sure that it would show up).

Here's the code for the click handler:

someHolder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LayoutInflater layoutSeed = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View baseView = layoutSeed.inflate(R.layout.activity_listings, null, false);
            RelativeLayout popup = (RelativeLayout) baseView.findViewById(R.id.popupContainer);
            Log.d("Tag1",Integer.toString(popup.getVisibility()));
            popup.setVisibility(View.VISIBLE);
            Log.d("Tag2",Integer.toString(popup.getVisibility()));
        }
});

Logcat shows the status change. I've also tried to invalidate() and postInvalidate() on both baseView and popup, as well as popup.bringToFront() and the combinations of these and so far nothing's working.

Any suggestions or possible routes to investigate?

Upvotes: 4

Views: 1898

Answers (4)

KALPESH VAGHELA
KALPESH VAGHELA

Reputation: 21

when you click on button your View is replace by button's OnClick(View v) method. so you just write down

v.popup(View.GONE)

Upvotes: 1

Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8190

Look at this line of code:

View baseView = layoutSeed.inflate(R.layout.activity_listings, null, false);
RelativeLayout popup = (RelativeLayout) baseView.findViewById(R.id.popupContainer);
Log.d("Tag1",Integer.toString(popup.getVisibility()));

Actually, you're trying to create a new baseView and set it gone. If you want to set the row item gone, you should remove it from your adapter temporary instead such as (if you set itemView to gone, you should be careful with the resuing view of the adapter):

removeItemAt(getAdapterPosition()) 
notifyDataRemoved(getAdapterPosition())

Upvotes: 0

Anooj
Anooj

Reputation: 61

If the RelativeLayout you are trying to change visibility is already in the screen, you don't need to inflate it again. Please make a reference to already inflated one and change its visibility

holder.relativeLayout.setVisibility(View.GONE);

Upvotes: 6

Matthew Xavier Jacome
Matthew Xavier Jacome

Reputation: 172

Gone will remove the view from your layout. Use Invisible instead of gone.

Upvotes: 2

Related Questions