Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetVisibility doesn't work?

I'm new to developing with android. I have a grid contained in a LinearLayout and each item which makes up the grid is a button. I want this LinearLayout to be invisible when the user pushes any of these buttons.

This is my 'home' layout shell:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
  <TextView/>
  <LinearLayout>   //<-- this is the layout I want to hide
     <TextView/>
     <GridView/>
  </LinearLayout>
</LinearLayout>

And this is the onClick method which I've set up in MyArrayAdapter (used to inflate buttons)

@Override
public void onClick(View v) {
   View convertView = activity.getLayoutInflater().inflate(R.layout.layout_home, null);  
   LinearLayout ll_options = (LinearLayout) convertView.findViewById(R.id.ll_options);
   ll_options.setVisibility(View.INVISIBLE);
}

I think it should work but when I test it, nothing happens.

I found a similar question but it doesn't solve my problem.

like image 251
dnaranjo Avatar asked Dec 27 '22 02:12

dnaranjo


1 Answers

Why are you inflating a layout here?:

View convertView = activity.getLayoutInflater().inflate(R.layout.layout_home, null);

Just do:

View v = activity.findViewById(R.id.ll_options);
v.setVisibility(View.INVISIBLE);
like image 66
gngr44 Avatar answered Jan 09 '23 05:01

gngr44