Implementation of check boxes part 2
===

hello I tinkered with the code i am providing two java files 1 which initializes the sqlitte database for the reminder app that i intend to create and the other is responsible for the edit body parameters i have a incorporated a check box and used ischecked method to assign a value to the string which is stored in the database the app is not able to store the status of the checkbox please help!
and thanx in advance

package com.taskreminder.sidharth;


//class for sql 

    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import android.widget.Button;
    import android.widget.CheckBox;
    
    /**
     * Simple reminder database access helper class. 
     * Defines the basic CRUD operations (Create, Read, Update, Delete)
     * for the example, and gives the ability to list all reminders as well as
     * retrieve or modify a specific reminder.
     * 
     */
    public class RemindersDbAdapter {
    
    	//
    	// Databsae Related Constants
    	//
    	private static final String DATABASE_NAME = "data";
        private static final String DATABASE_TABLE = "reminders";
        private static final int DATABASE_VERSION = 3;
        
    	public static final String KEY_TITLE = "title";
        public static final String KEY_BODY = "body";
        public static final String KEY_DATE_TIME = "reminder_date_time"; 
        public static final String KEY_STATUS = "status";
        public static final String KEY_ROWID = "_id";
        
        
        private static final String TAG = "ReminderDbAdapter";
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDb;
        
        /**
         * Database creation SQL statement
         */
        private static final String DATABASE_CREATE =
                "create table " + DATABASE_TABLE + " ("
                		+ KEY_ROWID + " integer primary key autoincrement, "
                        + KEY_TITLE + " text not null, " 
                        + KEY_BODY + " text not null, " 
                        + KEY_DATE_TIME + " text not null, "
                        
                        + KEY_STATUS + " text not null);" ;
    
        
    
        private final Context mCtx;
    
        private static class DatabaseHelper extends SQLiteOpenHelper {
    
            DatabaseHelper(Context context) {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
            }
    
            @Override
            public void onCreate(SQLiteDatabase db) {
    
                db.execSQL(DATABASE_CREATE);
            }
    
            @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 " + DATABASE_TABLE);
                onCreate(db);
            }
        }
    
        /**
         * Constructor - takes the context to allow the database to be
         * opened/created	
         * 
         * @param ctx the Context within which to work
         */
        public RemindersDbAdapter(Context ctx) {
            this.mCtx = ctx;
        }
    
        /**
         * Open the database. If it cannot be opened, try to create a new
         * instance of the database. If it cannot be created, throw an exception to
         * signal the failure
         * 
         * @return this (self reference, allowing this to be chained in an
         *         initialization call)
         * @throws SQLException if the database could be neither opened or created
         */
        public RemindersDbAdapter open() throws SQLException {
            mDbHelper = new DatabaseHelper(mCtx);
            mDb = mDbHelper.getWritableDatabase();
            return this;
        }
        
        public void close() {
            mDbHelper.close();
        }
    
    
        /**
         * Create a new reminder using the title, body and reminder date time provided. 
         * If the reminder is  successfully created return the new rowId
         * for that reminder, otherwise return a -1 to indicate failure.
         * 
         * @param title the title of the reminder
         * @param body the body of the reminder
         * @param reminderDateTime the date and time the reminder should remind the user
         * @return rowId or -1 if failed
         */
        public long createReminder(String title, String body, String status, String reminderDateTime) {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_TITLE, title);
            initialValues.put(KEY_BODY, body);
            initialValues.put(KEY_STATUS, status);
        
            initialValues.put(KEY_DATE_TIME, reminderDateTime); 
    
            return mDb.insert(DATABASE_TABLE, null, initialValues);
        }
    
        /**
         * Delete the reminder with the given rowId
         * 
         * @param rowId id of reminder to delete
         * @return true if deleted, false otherwise
         */
        public boolean deleteReminder(long rowId) {
    
            return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
        }
    
        /**
         * Return a Cursor over the list of all reminders in the database
         * 
         * @return Cursor over all reminders
         */
        public Cursor fetchAllReminders() {
    
            return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
                    KEY_BODY, KEY_DATE_TIME, KEY_STATUS}, null, null, null, null, null);
        }
    
        /**
         * Return a Cursor positioned at the reminder that matches the given rowId
         * 
         * @param rowId id of reminder to retrieve
         * @return Cursor positioned to matching reminder, if found
         * @throws SQLException if reminder could not be found/retrieved
         */
        public Cursor fetchReminder(long rowId) throws SQLException {
    
            Cursor mCursor =
    
                    mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                            KEY_TITLE, KEY_BODY, KEY_DATE_TIME, }, KEY_ROWID + "=" + rowId, null,
                            null, null, null, null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
    
        }
    
        /**
         * Update the reminder using the details provided. The reminder to be updated is
         * specified using the rowId, and it is altered to use the title, body and reminder date time
         * values passed in
         * 
         * @param rowId id of reminder to update
         * @param title value to set reminder title to
         * @param body value to set reminder body to
         * @param reminderDateTime value to set the reminder time. 
         * @return true if the reminder was successfully updated, false otherwise
         */
        public boolean updateReminder(long rowId, String title, String body,String status, String reminderDateTime ) {
            ContentValues args = new ContentValues();
            args.put(KEY_TITLE, title);
            args.put(KEY_BODY, body);
            args.put(KEY_DATE_TIME, reminderDateTime);
            args.put(KEY_STATUS,status);
    
    
            return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
        }
    }

// class for reminder body



    package com.taskreminder.sidharth;
    
    
    
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.app.TimePickerDialog;
    import android.content.SharedPreferences;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.preference.PreferenceManager;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.TimePicker;
    import android.widget.Toast;
    
    public class ReminderEditActivity extends Activity {
    
    	// 
    	// Dialog Constants
    	//
    	private static final int DATE_PICKER_DIALOG = 0;
    	private static final int TIME_PICKER_DIALOG = 1;
    	
    	// 
    	// Date Format 
    	//
    	private static final String DATE_FORMAT = "yyyy-MM-dd"; 
    	private static final String TIME_FORMAT = "kk:mm";
    	public static final String DATE_TIME_FORMAT = "yyyy-MM-dd kk:mm:ss";
    	
    	private EditText mTitleText;
        private EditText mBodyText;
        private Button mDateButton;
        private Button mTimeButton;
        private Button mConfirmButton;
        private Long mRowId;
        private RemindersDbAdapter mDbHelper;
        private Calendar mCalendar; 
        private CheckBox  mStatus;
      
        	
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
            mDbHelper = new RemindersDbAdapter(this);
            
            setContentView(R.layout.reminder_edit);
            
            mCalendar = Calendar.getInstance(); 
            mTitleText = (EditText) findViewById(R.id.title);
            mBodyText = (EditText) findViewById(R.id.body);
            mDateButton = (Button) findViewById(R.id.reminder_date);
            mTimeButton = (Button) findViewById(R.id.reminder_time);
            mStatus = (CheckBox) findViewById(R.id.checkBox1);
            mConfirmButton = (Button) findViewById(R.id.confirm);
         
           
            mStatus.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                //@Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    Boolean  checked;  
    				if(isChecked){
    					checked = mStatus.isChecked();
                      
                     }else{
                    	 checked = mStatus.isChecked();
    
                     }
                }
           });
    
            
    
          
    
           
            mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID) 
                    							: null;
          
            registerButtonListenersAndSetDefaultText();
        }
    
    	private void setRowIdFromIntent() {
    		if (mRowId == null) {
    			Bundle extras = getIntent().getExtras();            
    			mRowId = extras != null ? extras.getLong(RemindersDbAdapter.KEY_ROWID) 
    									: null;
    			
    		}
    	}
        
        @Override
        protected void onPause() {
            super.onPause();
            mDbHelper.close(); 
        }
        
        @Override
        protected void onResume() {
            super.onResume();
            mDbHelper.open(); 
        	setRowIdFromIntent();
    		populateFields();
        }
        
        @Override
        protected Dialog onCreateDialog(int id) {
        	switch(id) {
        		case DATE_PICKER_DIALOG: 
        			return showDatePicker();
        		case TIME_PICKER_DIALOG: 
        			return showTimePicker(); 
        	}
        	return super.onCreateDialog(id);
        }
        
     	private DatePickerDialog showDatePicker() {
    		
    		
    		DatePickerDialog datePicker = new DatePickerDialog(ReminderEditActivity.this, new DatePickerDialog.OnDateSetListener() {
    			
    			public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    				mCalendar.set(Calendar.YEAR, year);
    				mCalendar.set(Calendar.MONTH, monthOfYear);
    				mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    				updateDateButtonText(); 
    			}
    		}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); 
    		return datePicker; 
    	}
    
       private TimePickerDialog showTimePicker() {
    		
        	TimePickerDialog timePicker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
    			
    			public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    				mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
    				mCalendar.set(Calendar.MINUTE, minute); 
    				updateTimeButtonText(); 
    			}
    		}, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), true); 
    		
        	return timePicker; 
    	}
     	
    	private void registerButtonListenersAndSetDefaultText() {
    
    		mDateButton.setOnClickListener(new View.OnClickListener() {
    			
    			public void onClick(View v) {
    				showDialog(DATE_PICKER_DIALOG);  
    			}
    		}); 
    		
    		
    		mTimeButton.setOnClickListener(new View.OnClickListener() {
    			
    			public void onClick(View v) {
    				showDialog(TIME_PICKER_DIALOG); 
    			}
    		}); 
    		
    		mConfirmButton.setOnClickListener(new View.OnClickListener() {
            	public void onClick(View view) {
            		saveState(); 
            		setResult(RESULT_OK);
            	    Toast.makeText(ReminderEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
            	    finish(); 
            	}
              
            });
    		
    		  updateDateButtonText(); 
    	      updateTimeButtonText();
    	}
       
        private void populateFields()  {
        	
      	
        	
        	// Only populate the text boxes and change the calendar date
        	// if the row is not null from the database. 
            if (mRowId != null) {
                Cursor reminder = mDbHelper.fetchReminder(mRowId);
                startManagingCursor(reminder);
                mTitleText.setText(reminder.getString(
        	            reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_TITLE)));
                mBodyText.setText(reminder.getString(
                        reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_BODY)));
                
    
                // Get the date from the database and format it for our use. 
                SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
                Date date = null;
    			try {
    				String dateString = reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_DATE_TIME)); 
    				date = dateTimeFormat.parse(dateString);
    	            mCalendar.setTime(date); 
    			} catch (ParseException e) {
    				Log.e("ReminderEditActivity", e.getMessage(), e); 
    			} 
            } else {
            	// This is a new task - add defaults from preferences if set. 
            	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
            	String defaultTitleKey = getString(R.string.pref_task_title_key); 
            	String defaultTimeKey = getString(R.string.pref_default_time_from_now_key); 
            	
            	String defaultTitle = prefs.getString(defaultTitleKey, null);
            	String defaultTime = prefs.getString(defaultTimeKey, null); 
            	
            	if(defaultTitle != null)
            		mTitleText.setText(defaultTitle); 
            	
            	if(defaultTime != null)
            		mCalendar.add(Calendar.MINUTE, Integer.parseInt(defaultTime));
            	
            }
            
            updateDateButtonText(); 
            updateTimeButtonText(); 
            	
        }
    
    	private void updateTimeButtonText() {
    		// Set the time button text based upon the value from the database
            SimpleDateFormat timeFormat = new SimpleDateFormat(TIME_FORMAT); 
            String timeForButton = timeFormat.format(mCalendar.getTime()); 
            mTimeButton.setText(timeForButton);
    	}
    
    	private void updateDateButtonText() {
    		// Set the date button text based upon the value from the database 
            SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); 
            String dateForButton = dateFormat.format(mCalendar.getTime()); 
            mDateButton.setText(dateForButton);
    	}
        
        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            outState.putLong(RemindersDbAdapter.KEY_ROWID, mRowId);
        }
        
    
        
        private void saveState() {
            String title = mTitleText.getText().toString();
            String body = mBodyText.getText().toString();
            String status="null";
          
            if (mStatus.isChecked())
            {
            	 status ="1";
            	
            }else
            {
            	 status = "0";
            }
            
            SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT); 
        	String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());
    
            if (mRowId == null) {
            	
            	
    			long id = mDbHelper.createReminder(title,  body, status, reminderDateTime);
                    mRowId = id;
                }
              else {
                mDbHelper.updateReminder(mRowId, title, body, status, reminderDateTime);
            }
           
            new ReminderManager(this).setReminder(mRowId, mCalendar); 
        }
        
    }
    
     



