如何设置按钮的可见性在自定义的ListView? [英] How to set the visibilty of button in a custom ListView?
问题描述
我有一个自定义的的ListView
与按钮
,所以当我点击一个按钮
就应该消失,它正在消失,但是当我向下滚动,回来按钮
再次出现和不同的按钮
是越来越消失了。我怎样才能让特定的按钮
来消失点击....我用这code
holder.checkbox =(按钮)view.findViewById(R.id.checkBox1);holder.checkbox.setOnClickListener(新View.OnClickListener(){@覆盖
公共无效的onClick(视图v){
holder.checkbox.setVisibility(View.INVISIBLE);
在ListView的项目时熄灭屏幕,对于效率的ListView破坏的项目和滚动回到它通过调用getView重新创建该项目时()方法适配器,所以你必须保持有该按钮默认情况下是状态的布尔数组将作为可见光和getView()你只要把支票从布尔数组获得的状态布尔值true,如果真,那么项目是可见的其他项目是看不见的。所以,当你消失了一个项目,你必须设定的项目也是假的状态。
我认为这是在你的getView(在code)以及您已经使用相同长度的ListView和的真正价值的项目名称为yourButtonStatusBooleanArray,那么以下修改会为你工作定义你的布尔数组。
holder.checkbox =(按钮)view.findViewById(R.id.checkBox1);如果(!yourButtonStatusBooleanArray [位置])
{
holder.checkbox.setVisibility(View.INVISIBLE);
}
holder.checkbox.setOnClickListener(新View.OnClickListener(){@覆盖
公共无效的onClick(视图v){
holder.checkbox.setVisibility(View.INVISIBLE);
yourButtonStatusBooleanArray [位置] = FALSE;
I have a custom ListView
with a button
, so when I click on a button
it should disappear and it is disappearing but when I scroll down and come back the button
is again appearing and a different button
is getting disappeared. How can i make the specific button
to disappear on clicking.... I am using this code
holder.checkbox = (Button) view.findViewById(R.id.checkBox1);
holder.checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.checkbox.setVisibility(View.INVISIBLE);
In ListView when an item goes out of screen, for efficiency ListView destroys the item and when scrolling back to that item it recreates it by calling getView() method of adapter so you have to keep an array having a boolean for the status of the button which is by default will be true as for visible and in getView() you just put a check by getting the boolean value of status from the boolean array that if true then item is visible else item is invisible. So when you disappear an item you have to set status of item also false. I assume this is the code in your getView() and you have already defined your array of boolean with same length as items of ListView and value of true with name "yourButtonStatusBooleanArray" then following modifications will work for you.
holder.checkbox = (Button) view.findViewById(R.id.checkBox1);
if(!yourButtonStatusBooleanArray[position])
{
holder.checkbox.setVisibility(View.INVISIBLE);
}
holder.checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.checkbox.setVisibility(View.INVISIBLE);
yourButtonStatusBooleanArray[position]=false;
这篇关于如何设置按钮的可见性在自定义的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!