0

我有列表视图布局(如下所示),默认情况下图像按钮不可见,并且在用户单击列表行项目时可见。

----------------------------------
|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 设置为不可见。

4

1 回答 1

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;
    }
});
于 2013-08-06T14:16:30.973 回答