我有listview布局(如下所示),默认情况下图像按钮不可见,当用户点击listrow项目时可见。
----------------------------------
|TextView | ImageButton |
----------------------------------
mylist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
view.setSelected(true);
ImageButton btnChild = (ImageButton)view.findViewById(R.id.playbtn);
btnChild.setVisibility(View.VISIBLE);
}
});
我想在用户选择不同的列表项时将Imagebutton设置为不可见。
答案 0 :(得分:0)
存储对最新所选项目的引用并更改您的代码:
View latestSelected;
.
.
.
mylist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
view.setSelected(true);
ImageButton btnChild = (ImageButton)view.findViewById(R.id.playbtn);
btnChild.setVisibility(View.VISIBLE);
if (latestSelected != null){
ImageButton btnChild1 = (ImageButton)latestSelected.findViewById(R.id.playbtn);
btnChild1.setVisibility(View.INVISIBLE);
}
latestSelected = view;
}
});