Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.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中从ListView中删除项目_Android_Android Listview - Fatal编程技术网

在Android中从ListView中删除项目

在Android中从ListView中删除项目,android,android-listview,Android,Android Listview,我有一个列表视图,其中包含一个项目名称和项目名称前的复选框,以及布局下方的一个删除按钮。如果我的列表包含15个项目,则只有10个项目可见。当我向下滚动并选中第15个项目,然后按删除按钮时,它将在复选框上引发空指针异常。下面是我使用复选框从列表视图中删除项目的代码 deleteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Sy

我有一个列表视图,其中包含一个项目名称和项目名称前的复选框,以及布局下方的一个删除按钮。如果我的列表包含15个项目,则只有10个项目可见。当我向下滚动并选中第15个项目,然后按删除按钮时,它将在复选框上引发空指针异常。下面是我使用复选框从列表视图中删除项目的代码

deleteButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View view) {
        System.out.println("Cursor length is " + cursor.getCount());
        for (int i = 1; i <= cursor.getCount(); i++) {
            listData.recomputeViewAttributes(view);
            listData.getResources();
            listData.smoothScrollToPosition(i);
            view = listData.getChildAt(i-1);

            System.out.println("Count is "+i);
            CheckBox box = (CheckBox) view.findViewById(R.id.checkBox1);
            if (box.isChecked()) {

                System.out.println("Box Checked");

                /*cursor.moveToPosition(i);
                int id = cursor.getInt(0);
                System.out.println("Id is " + id);
                controller.deleteBookmarkOnId(id);*/
            }
        }
        dialog.dismiss();
    }
});
deleteButton.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图){
System.out.println(“游标长度为”+Cursor.getCount());

对于(int i=1;i而言,
findViewById
方法不应在输入中采用“位置”(如
i-1
),而应采用您的资源包中的ID,如
R.ID。请选中此复选框