我有一个 ListView ,当单击它时它必须是不可见的。它工作得很好,但是当屏幕上下滚动时,那些不可见的内容会再次出现。有谁知道如何解决这些问题。
这是我的 ListItemClick 代码 fragment
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
v.setVisibility(View.GONE);
Object o = this.getListAdapter().getItem(position);
Contact1 c = (Contact1) o;
Toast.makeText(this, c.getDisplayName(),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, c.getId(), Toast.LENGTH_SHORT).show();
ids.add(c.getDisplayName());
}
最佳答案
发生这种情况是因为每次滚动列表时,都会调用 ListView 适配器的 getView()
方法,并再次生成列表项。因此,根据您的需要,您需要有一个自定义适配器并覆盖其 getView
方法,并在其中
@override
public View getView(View view) //Just a mock method, do not copy paste
{
if(!isVisible[position]){ // isVisible is an array which holds whether a view at position is visible or not
//make it invicsible here
}
return view;
}
关于android - 单击后隐藏 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12274355/