I want to create a sample database application to add/edit/delete
record. I want to know that how to edit record when click on item. my
application  is below


package ost.android.DatabaseTest;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class EmployeeList extends ListActivity {

        DatabaseHelper dbHelper;
        private Cursor mNotesCursor;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.list_example);


        dbHelper=new DatabaseHelper(this);
        try
        {

                mNotesCursor=dbHelper.getAllEmployees();
                startManagingCursor(mNotesCursor);



                String [] from=new String []
{DatabaseHelper.colName,DatabaseHelper.colMobile};
                int [] to=new int [] {R.id.colName,R.id.colMobile};
                SimpleCursorAdapter sca=new
SimpleCursorAdapter(this,R.layout.employeelist,mNotesCursor,from,to);
                        this.setListAdapter(sca);





        }
        catch(Exception ex)
        {
                AlertDialog.Builder b=new AlertDialog.Builder(this);
                b.setMessage(ex.toString());
                b.show();
        }



    }


    @Override
        protected void onListItemClick(ListView listView, View v, int
position, long id) {
                super.onListItemClick(listView, v, position, id);
                // Get the item that was clicked
                //String selection =
listView.getItemAtPosition(position).toString();


                Intent intent = new Intent(this, EmployeeEdit.class);
                intent.putExtra(DatabaseHelper.colID, id);
                // Activity returns an result if called with 
startActivityForResult

                startActivity(intent);


    }


}


Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to