how to add a checkbox in a listview?

后端 未结 5 1172
长发绾君心
长发绾君心 2021-01-06 15:34

i have a question, been stuck for a while, i dont know how can i add a checkbox in the list, for example if I have a list of items i want to be able to check them. my xml c

5条回答
  •  爱一瞬间的悲伤
    2021-01-06 16:23

    public class myAdapter extends SimpleCursorAdapter {
        public myAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) {
            super(context, layout, cursor, from, to);  
    }
    
    @Override   
    public void bindView(View view, Context context, Cursor cursor) {
        cb=(CheckBox)view.findViewById(R.id.cb);
        cb.setText(dbgetStringValue);
        cbText=(TextView)view.findViewById(R.id.cbText);
                cbText.setText(dbgetStringValue);
        cb.setChecked(false);
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton cb, boolean isChecked) {            
                if(cb.isChecked()) {                    
                    // action
                }
                else if(isChecked==false) {
                    // action
                }
            }           
        });
    }
    } 
    

    is that what you want?

提交回复
热议问题