2014-07-21 88 views
2

在列表项中有两个按钮buton1和button2。
在button1上单击我想仅显示该行的button2。 这是通过将button2的实例设置为button1的标记,然后在button1的onClickListener上使用getTag获取button1并更改其可见性来实现的。第一季度:有没有更好的方法来做到这一点?
Q2:在滚动中,由于我使用视图持有者模式并重用了这些行,所以在列表中某些行的其他位置显示的button2被关闭。
列表项布局视图show hide

有人吗?

回答

1

您需要在适配器的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; 

} 
+0

喜,上述样品dowsnt回答我的第二个问题Q2:在滚动,因为我使用的观点持有者模式和重用的行,即在某些行被显示在别处列表获取BUTTON2关闭。 – chaitanyad

+0

,我将不得不声明button2作为最终使用它在侦听器中。那是什么意思? – chaitanyad