列表项布局视图显示隐藏

时间:2014-07-21 14:12:34

标签: android listview baseadapter

在列表项中有两个按钮buton1和button2。
在按钮1上单击我想仅显示该行的button2。 这是通过将button2的实例设置为button1的标签,然后在button1的onClickListener上使用getTag获取button1并更改其可见性来实现的。 Q1:有更好的方法吗?
Q2:在滚动时,由于我使用视图持有者模式并重新使用行,因此列表中某些行中其他位置显示的按钮2将被关闭。

任何?

1 个答案:

答案 0 :(得分:1)

您需要在Adapter的getView回调中处理它。类似的东西:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;

    LayoutInflater vi;
    vi = LayoutInflater.from(getContext());
    v = vi.inflate(R.layout.itemlistrow, null);
    Button button1 = (Button) v.findViewById(R.id.button1);
    Button button2 = (Button) v.findViewById(R.id.button2);
    button1.setOnClickListener(new OnClickListener() {
         public void onClick(View v)
         {
             button2.setVisibility(View.VISIBLE);
         } 
    });


    return v;

}
相关问题