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

6/1/12

How to make activity to appear in Dialog style

If you want activity to upear like picture below
 
You need to modifiy  activity definition inside  AndroidManifest as  following  :


<activity android:name=".ItemEdit" android:theme="@android:style/Theme.Dialog"></activity>



As you can see - the 'Edit Item' screen is ready now. you can modify here the name of item and quantity.

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...