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.

5/31/12

How to add a new activity

When you adding new activity to project you must register it in AndroidManifest.xml.


    

    
        
            
                
                
            
        
        
        
    



I have wasted a lot of time before i figured it out, when tried to create EditItem activity.

5/25/12

Notepad Sample application-used inspiration for me

I have learned a lot from exploring Notepad Sample application from SDK samples . If you want to import it to your local namespace in Eclipse you only need:
in dialog that opens you have to select 'from exisitng sample':
choose tagret system and in the next dialog-many samples you can import and play with:

5/22/12

Database structure

Database structure of application will be as much simple as possible:
There will be two tables: lists and items :
Usualy, in android, SqlLite database is used. Here is the code i wrote for creating the database :

 //create lists table
 private static final String LISTS_TABLE_CREATE =
 "create table lists ("
 +"_id integer primary key autoincrement, "
 +" listName text not null"
 +" );";
 
 //create items table
 private static final String ITEMS_TABLE_CREATE =
 "create table list_items ("
 +"_id integer primary key autoincrement, "
 +" isdone boolean  not null DEFAULT false,"
 +" title text not null,"
 +" list_id integer,"
 +" quantity integer not null DEFAULT 1,"
 +" FOREIGN KEY(list_id) REFERENCES lists(_id)" 
 +" );";  

 
 private final Context context;
 private DatabaseHelper DBHelper;
 private SQLiteDatabase db;
 public DBAdapter(Context ctx)
 {
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
 } 
 
 
 
 
 private static class DatabaseHelper extends SQLiteOpenHelper
 {
  DatabaseHelper(Context context)
  {
     super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  @Override
  public void onCreate(SQLiteDatabase db)
  {
   
     try {
      
      db.execSQL(LISTS_TABLE_CREATE );
      db.execSQL(ITEMS_TABLE_CREATE );
      
   } 
      catch (Exception e){
       e.printStackTrace();
   }
  }
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)  
  {/*
   Log.w(TAG, "Upgrading database from version " + oldVersion
   + " to "
   + newVersion + ", which will destroy all old data");*/
   db.execSQL("DROP TABLE IF EXISTS " + ITEMS_TABLE_NAME);
   db.execSQL("DROP TABLE IF EXISTS " + LISTS_TABLE_NAME);
   onCreate(db);
  }
 } 

5/20/12

How to make screen (or window) in Adndroid

In android programming, screen or window object named Activity.
Here is example code that display list of items from simple strings array :
public class NisuiActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ListView lv= (ListView)findViewById(R.id.listview);

        

        // create the grid item mapping

        String[] from = new String[] {"rowid"};
        int[] to = new int[] { R.id.item1 };

 

        // prepare the list of all records

        List<hashmap<string, string>> fillMaps = new ArrayList<hashmap<string, string>>();

        for(int i = 0; i < 10; i++){

            HashMap<string, string> map = new HashMap<string, string>();
            map.put("rowid", "" + i);

            fillMaps.add(map);

        }

 

        // fill in the grid_item layout
        SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
        lv.setAdapter(adapter);        
        
        
    }

}

When you run the code you got something like this:

5/17/12

Planing Design

Now i'm trying to plan the views.
I think the application will consist from two views:
1.  all the lists (for managing all lists)
2.  items of current list (for managing items)
I'm not good designer at all, as you can see from my design.
But here is all list screen:
And here is Items screen - where user will be able to check , delete and edit items:


5/16/12

Open repository at Github

In purpose to do things in a professional way (like many other decent developers) - i decided to open my own repository at github. In github the source will be accessible to everyone who want to see it
Today i created my first repository , and you can see the source here, or download it by press ZIP button





5/15/12

The Very simple android app i desided to build

I decided to build simple android  shopping list application, to try my skills in this  hot programming field.
Since I'm completely new to android and to java it is very interesting experiment if i will succeed...
The shopping  list application -is for help the people who going to shop, to remember what they planned  to buy.

Something like Out Of Milk Application (No way my application will be good as OutOfMilk, but i must start somewhere if i want to learn android development...)

All the products the user plan to buy are displayed in list  along with 'done' checkbox - which indicates if product is already in the cart.

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