gpt4 book ai didi

android - 单击后隐藏 ListView

转载 作者:行者123 更新时间:2023-11-29 00:36:39 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com