Android 如何使用游标适配器从存储在数据库中的listView中获取选定项?

Android 如何使用游标适配器从存储在数据库中的listView中获取选定项?,android,listview,Android,Listview,如何从列表视图(从复选框中选择的视图)中获取所选项目? 我从CursorAdapter中的处理程序中获得了一些结果 public class MyCursorAdapter extends CursorAdapter { @SuppressWarnings("deprecation") public MyCursorAdapter(Context context, Cursor c) { super(context, c); // TODO Auto-generated con

如何从
列表视图
(从复选框中选择的视图)中获取所选项目? 我从
CursorAdapter
中的
处理程序中获得了一些结果

public class MyCursorAdapter extends CursorAdapter {

@SuppressWarnings("deprecation")
public MyCursorAdapter(Context context, Cursor c) {
    super(context, c);
    // TODO Auto-generated constructor stub
}

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    TextView item=(TextView)view.findViewById(R.id.item_tv);
    CheckBox cb=(CheckBox)view.findViewById(R.id.flag_cb);

    item.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));

    Log.d("Bind View", "Flag="+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2))));

    if(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))).equalsIgnoreCase("true")){
        cb.setChecked(true);
    }else{
        cb.setChecked(false);
    }

    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            DatabaseHelperSQL help=new DatabaseHelperSQL(context);
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                Toast.makeText(context, "Check", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(context, "unCheck", Toast.LENGTH_LONG).show();
            }
        }   

    });

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater=LayoutInflater.from(parent.getContext());
    View retView=inflater.inflate(R.layout.every_row,parent,false);
    return retView;
}

}

这取决于您具体需要什么:

如果需要所选项目的ID,可以使用
boolean[]selected
,它将存储每个项目的状态

如果需要获取完全选定的项目,可以使用
列出选定的项目

输入一次检查更改
并在需要时返回

。回答了一个类似的问题。检查这个