Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 755
L. Thane Avatar asked Jan 03 '23 06:01

L. Thane


2 Answers

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);
like image 155
Anooj Avatar answered Feb 01 '23 13:02

Anooj


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

like image 32
Matthew Xavier Jacome Avatar answered Feb 01 '23 15:02

Matthew Xavier Jacome