6/5/12

Bind checkbox in listview

Because the screen i want to build must contain checkboxes inside listitems

 I decided not to use SimpleCursorAdapter for populating listview as in Notepad code sample :

 

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
                new String[] { NoteColumns.TITLE }, new int[] { android.R.id.text1 });
        setListAdapter(adapter);

Instead i'm using custom cursor adapter:
     
    MyAdapter items = new MyAdapter(this, c);
      
         setListAdapter(items);        

    }
    
    private class MyAdapter extends ResourceCursorAdapter {

        public MyAdapter(Context context, Cursor cur) {
            super(context, R.layout.list_item, cur);
        }

        @Override
        public View newView(Context context, Cursor cur, ViewGroup parent) {
            LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            return li.inflate(R.layout.list_item, parent, false);
        }

        @Override
        public void bindView(View view, Context context, Cursor cur) {
         TextView tvQuantityText = (TextView)view.findViewById(R.id.txtQuantity);
            TextView tvListText = (TextView)view.findViewById(R.id.text1);
            CheckBox cbListCheck = (CheckBox)view.findViewById(R.id.chkIsDone);

            
            
            tvListText.setText(cur.getString(cur.getColumnIndex(DBAdapter.KEY_TITLE)));
            tvQuantityText.setText(cur.getString(cur.getColumnIndex(DBAdapter.KEY_QUANTITY)));
            cbListCheck.setChecked((cur.getInt(cur.getColumnIndex(DBAdapter.KEY_ISDONE))==0? false:true));
            
            final int  rowID = cur.getInt(cur.getColumnIndex(DBAdapter.KEY_ROWID));
            //checkbox click
            cbListCheck.setOnClickListener( new View.OnClickListener() {  
                public void onClick(View v) {  
                    CheckBox cb = (CheckBox) v ;  
                    SaveDone(cb.isChecked(), v.getContext(), rowID);
                  }  
                }); 
         
        }

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...