gpt4 book ai didi

java - 在 ListView 的 ListItem 中删除和取消删除

转载 作者:行者123 更新时间:2023-11-30 04:32:47 25 4
gpt4 key购买 nike

我有一些功能可以在单击列表项时删除和取消删除 ListView 。我的代码在这里:

public void markComplete(View v)
{
Button b1 = (Button)findViewById(R.id.Completeit);
Button b2 = (Button)findViewById(R.id.InCompleted);


try{
TextView tv = (TextView)findViewById(R.id.textViewx);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}catch(Exception e){e.printStackTrace();}

b1.setVisibility(-1);
b2.setVisibility(1);

}

public void markInComplete(View v)
{
Button b1 = (Button)findViewById(R.id.Completeit);
Button b2 = (Button)findViewById(R.id.InCompleted);


try{
TextView tv = (TextView)findViewById(R.id.textViewx);
tv.setPaintFlags( tv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}catch(Exception e){e.printStackTrace();}
b1.setVisibility(1);
b2.setVisibility(-1);
}

我有两个按钮用于选中和取消选中列表项。它仅适用于第一个列表项。如果我尝试单击第二个列表项,则只在第一个项目上进行删除和取消删除。感谢您的帮助,并提前致谢

最佳答案

您的 findViewById 调用将返回它在 View 中找到的第一个元素。如果您有多个,那么这将是一个问题。它总是会找到第一个表格单元格。这里的解决方案是保存您的按钮,并将每个单元格视为一个单独的 View 。

关于java - 在 ListView 的 ListItem 中删除和取消删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7398312/

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