0

如何从中获取所选项目ListView(从复选框中选择视图)?我HandlerCursorAdapter.

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;
}

}
4

1 回答 1

0

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

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

如果您需要获得完全选择的项目,您可以使用List<View> selected

放入 onCheckedChanged
并在需要时返回

于 2013-08-15T10:17:30.233 回答