SetVisibility不起作用?

dna*_*njo 4 layout android visibility

我是开发android的新手.我有一个网格包含在一个网格中,构成网格的LinearLayout每个项目都是一个按钮.LinearLayout当用户按下任何这些按钮时,我希望它不可见.

这是我的'home'布局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>
Run Code Online (Sandbox Code Playgroud)

这是我在MyArrayAdapter中设置的onClick方法(用于膨胀按钮)

@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);
}
Run Code Online (Sandbox Code Playgroud)

我认为它应该可以工作,但是当我测试它时,没有任何反应.

我发现了一个类似的问题,但它并没有解决我的问题.

gng*_*r44 8

你为什么在这里给布局充气呢?:

View convertView = activity.getLayoutInflater().inflate(R.layout.layout_home, null);
Run Code Online (Sandbox Code Playgroud)

做就是了:

View v = activity.findViewById(R.id.ll_options);
v.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)