SimpleCursorAdapter and OnListItemClick - Simple question

by Gavin Aiken » Mon, 09 Mar 2009 03:57:05 GMT


Sponsored Links
 Hi guys,

I use a SimpleCursorAdapter like this;

        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                this.getIntent().getIntExtra("category", -1);
                Integer category = this.getIntent().getIntExtra("category",
-1);
                SqliteFilterMediator mediator = new
SqliteFilterMediator(this);
                ListAdapter adapter =
                        new SimpleCursorAdapter(this,
                                        R.layout.row,
                                        c,
                                        new String[] {column},
                                        new int[] {R.id.name});
                setListAdapter(adapter);
        }

        public void onListItemClick(ListView parent, View v, int position,
long id) {
           // Position doesn't necessarily map to _id
            setResult(RESULT_OK, this.getIntent().putExtra("_id",
position));
            finish();
        }

I want to return the 'id' which is paired with the text on the ListItem in
the database (And in the cursor). Currently I return the position of the
list item clicked.

The cursor might return items with ids that are out of order with the
position of the list, or it could contain gaps in the sequence of integers,
as such the position isn't enough to map to the id of the row selected in
the database so that I can act acordingly.

I hope my situation makes sense, I think it might involve displaying the id,
casing the view clicked and somehow grabbing the displayed integer back as
the id, this seems a bit ridiculous though so I'm hoping there is a simpler
way to retrieve the id without making another database query.

Many thanks!

Gav

--~--~---------~--~----~------------~-------~--~----~



SimpleCursorAdapter and OnListItemClick - Simple question

by Gavin Aiken » Mon, 09 Mar 2009 05:58:03 GMT


 This works for me;

    private Cursor c;
    @Override
    public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            Integer category = this.getIntent().getIntExtra("category", -1);
            mediator = new SqliteMediator(this);
            c = mediator.getFitlerNames(category);
            ListAdapter adapter =
                    new SimpleCursorAdapter(this,
                                    R.layout.row,
                                    c,
                                    new String[] {column},
                                    new int[] {R.id.name});
            setListAdapter(adapter);
    }

    public void onListItemClick(ListView parent, View v, int position, long
id) {
        c.moveToPosition(position);
        int filterId = c.getInt(0);
        c.close();
        mediator.onStop();
        setResult(RESULT_OK, new Intent().putExtra("_id", filterId));
        finish();
    }





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Se s

Dear *.*,

I am trying to create a rotationmatrix, to know and see how the phone
is rotating.
I didn't quite find any examples of how that could be used. I do have
the data values of the accelerometer and the magnetic field values,
however they are not aligned in time. So I have two questions:

- Is it possible to get the different sensor data values at a fixed
time;
  e.g. To read the accelerometer and magnetic field values at the same
time?

- How to retrieve the rotation-matrix by using the getRotationMatrix()
function when we don't have aligned data.

Thanks in advance. :-)

Derawi

--~--~---------~--~----~------------~-------~--~----~

2. From XML schemas to Android-Java classes for optimizing XML parsing and browsing

Hi!
My application has to handle many XML documents based on various XML
schemas (XSD). I am looking for tools/libraries, running on Android,
and that enable to convert efficiently XML docs into Java objects
based on a pre-generated classes from XSD shemas (equivalent of xml-
beans? castor? JiBX?) ?? For instance, I parse and browse XML thanks
to Android parsers, but are there any XML cool tools?
I tried JiBX on Android, without sucess. Does someone?

Thks

Regards,

JB

--~--~---------~--~----~------------~-------~--~----~

3. Anybody create local app in android source code?

4. How to get class com.android.testharness to do unit performance test?

5. HTTPS + Sync Ajax == Frozen Cupcake Browser

6. Google app for you domain

7. Android Mediaplayer setdatasource(String) issue