Hi,

I am having problems figuring out how to get some information from a
list I've created. I'm trying to retrieve the _ID, which is the
primary key of my database so that I can use it as a parameter to pass
to either a method to delete or to another class to do an update.
My code is below any help will be much appreciated

package inc1.proto2;

import static android.provider.BaseColumns._ID;
import static inc1.proto2.Constants.TABLE_NAME;
import static inc1.proto2.Constants.TITLE;
import static inc1.proto2.Constants.TIME;
import static inc1.proto2.Constants.STARTTIME;
import static inc1.proto2.Constants.ENDTIME;
import static inc1.proto2.Constants.REMINDERTIME;
import inc1.proto2.EventsData;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.UrlQuerySanitizer.ValueSanitizer;
import android.os.Bundle;
import android.widget.Toast;

public class Read extends ListActivity
{
        private static String[] FROM = { _ID, TIME, TITLE, STARTTIME,
ENDTIME, REMINDERTIME };
        private static String ORDER_BY = _ID + " ASC";
        private static int[] TO = { R.id.rowid, R.id.time, R.id.title,
R.id.starttime,
                                                           R.id.endtime, 
R.id.reminder};
        private EventsData events;

        public void onCreate(Bundle icicle)
        {
                super.onCreate(icicle);
                setContentView(R.layout.read);
                events = new EventsData(this);
                try
                {
                        Cursor cursor = getEvents();
                        showEvents(cursor);
                }
                finally
                {
                        events.close();
                }
        }

        private Cursor getEvents()
        {
                // Perform a managed query. The Activity will handle closing
            // and re-querying the cursor when needed.
            SQLiteDatabase db = events.getReadableDatabase();
            Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null,
                                        null, ORDER_BY);
            startManagingCursor(cursor);
            return cursor;
        }

        private void showEvents(Cursor cursor)
        {
                // Set up data binding
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                                                                R.layout.item, 
cursor, FROM, TO);
           setListAdapter(adapter);
        }

        protected void onListItemClick(ListView l, View v, int position, long
id)
        {
                super.onListItemClick(l, v, position, id);

                final String testPosID  = String.valueOf(l.getId());

                new AlertDialog.Builder(this)
        .setTitle(R.string.manage_title)
        .setItems(R.array.UDOptions,
        new DialogInterface.OnClickListener()
        {
                public void onClick(DialogInterface dialoginterface, int i)
                {
                        // 0 = Update 1 = Delete

                        if (i == 0){

                                Toast.makeText(Read.this,
                                " UPDATE",Toast.LENGTH_LONG).show();
                        }

                        if (i == 1){
                                Toast.makeText(Read.this,
                        testPosID,Toast.LENGTH_LONG).show();
                        }

                }
        })
        .show();
        }
}

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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to