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

Hi,

Can anyone suggest me that is there any difference between android phone &
android tablet in application development.
I want to develop an application for android tablet.

so plz tell me that what should know me regarding general info to develop
application for android tablet.

can i use same AVD with appropriate resolution for it?
can i use same project structure of android phone to android tablet?

please help me.

Regards

Ravi Shankar Kumar

-- 

2. Messing with .ap

Dear All,

I was trying to see when the android package installer allows/rejects .apk.

My first attempt was to simply "hexedit" on a .apk and see what happens
during :

adb install xxx.apk

I get this error: INSTALL_PARSE_FAILED_NO_CERTIFICATES

which surprises me. I thought it would fail at the verification of JAR..

So I would like somebody throw light on the whole process:

A JAR file of the .apk(the App) creates an archive file which is then signed
with the private key of the creator of JAR and the signature of the JAR is
verified with the public key.
 The certificate is a statement from the owner of the private key that the
public key in the pair has a particular value so the person using the public
key can be assured the public key is authentic.

How is changing a hex value on the apk ( I would assume as manipulating the
apk, and therefore would not be verified well) giving such an error as
above?


Thanks in advance

-- 

3. get name of list item

4. WTHelp : Gprs HD2 gak mau konek..

5. Code for capturing the screenshot of live wallpaper

6. How to do selective "compiling" in Android

7. who can give me some example to show how to use EGLimage?