Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android CheckedTextView_Android_Listview_Android Listview_Checkedtextview - Fatal编程技术网

Android CheckedTextView

Android CheckedTextView,android,listview,android-listview,checkedtextview,Android,Listview,Android Listview,Checkedtextview,我有一个listview,其中包含一个checkedtextview。我的应用程序从列表视图的顶部移动到底部。我想在调用操作之前检查项目是否已检查。如果没有选中,我想转到列表中的下一项 例如 项目1-已检查 项目2-已检查 第3项-未检查 项目4-已核对 因此,我希望应用程序按如下方式处理: Is Current Item checked? Yes: Call action No: Move to next item. Reloop to top of void. 项目1 项目2 项目4 我不

我有一个
listview
,其中包含一个
checkedtextview
。我的应用程序从列表视图的顶部移动到底部。我想在调用操作之前检查项目是否已检查。如果没有选中,我想转到列表中的下一项

例如

项目1-已检查

项目2-已检查

第3项-未检查

项目4-已核对

因此,我希望应用程序按如下方式处理:

Is Current Item checked?
Yes:
Call action
No:
Move to next item.
Reloop to top of void.
项目1

项目2

项目4

我不确定如何从
列表视图
位置访问项目的已检查状态

我想要的逻辑如下:

Is Current Item checked?
Yes:
Call action
No:
Move to next item.
Reloop to top of void.

我需要一些东西来阻止无限循环。

一个解决方案是使用位置的
ArrayList
。 当用户选中/取消选中
复选框时,相应地添加/删除
数组列表中的位置。
然后,当用户结束时,只需在列表中循环以了解已选择的位置。

1。)首先创建一个数组,该数组指示适配器中的项目选中状态

(假设为此扩展了
BaseAdapter
类):

2。)然后在checkedChangeListener上创建一个

private OnCheckedChangeListener listener = new OnCheckedChangeListener()
{
    @Override
    public void onCheckedChanged(CompoundButton button, boolean checked)
    {
        Integer index = (Integer)button.getTag();
        itemsChecked[index] = checked;
    }
}
3。)在适配器中
getView()
方法:

public View getView(int index, View view, ViewGroup parent)
{
    /*...*/
    CheckBox checkBox = /*get the checkbox*/;
    checkbox.setTag(index); 
    checkBox.setOnCheckedChangeListener(listener);
    /*...*/
}
public void onClick(View view)
{
    //just get the boolean array somehow
    boolean [] itemsChecked = adapter.getItemsCheckedArray(); 

    for(int i=0; i<itemsChecked.length; i++)
    {
        if(itemsChecked[i])
        {
            //the i th item was checked
        }
        else
        {
                //it isnt checked
        } 
    }
}
4。)
onClick()方法中:

public View getView(int index, View view, ViewGroup parent)
{
    /*...*/
    CheckBox checkBox = /*get the checkbox*/;
    checkbox.setTag(index); 
    checkBox.setOnCheckedChangeListener(listener);
    /*...*/
}
public void onClick(View view)
{
    //just get the boolean array somehow
    boolean [] itemsChecked = adapter.getItemsCheckedArray(); 

    for(int i=0; i<itemsChecked.length; i++)
    {
        if(itemsChecked[i])
        {
            //the i th item was checked
        }
        else
        {
                //it isnt checked
        } 
    }
}
public void onClick(视图)
{
//只需以某种方式获取布尔数组
布尔值[]itemsChecked=adapter.getItemsCheckedArray();

对于(int i=0;iSo),在onclicklistener中,构建一个选中项目位置的数组列表?然后,根据该列表测试当前项目位置。如果它在列表中,请继续操作?如果它不在列表中,我如何重新启动?这个问题已经问了很多,请参阅此处了解更多详细信息