1. Download our Official Android App: Forums for Android!

Apps listview onclick question

Discussion in 'Android Development' started by creatiive, Jan 30, 2010.

  1. creatiive

    creatiive Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Jan 14, 2010

    Jan 14, 2010
    7
    0
    5
    hey,

    I have populated my list using a SimpleCursorAdapter with info from my sqlite database;

    Code (Text):
    1.  
    2. SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.row, c, from, to);
    3. setListAdapter(sca);
    4.  

    This successfully populates my views in the row.xml with the fields i get from the database! Now, my question is probably ridiculously easy, but im having trouble with actually getting the item-specific info when the list item is clicked in my onListItemClick method;



    Code (Text):
    1.  
    2. public void onListItemClick(ListView parent, View v, int position, long id) {
    3. Intent intent = new Intent(this,Log.class);
    4. intent.putExtra("itemID",0);
    5. startActivity(intent);[/LEFT]
    6. }
    7. [LEFT]

    Essentially, where the '0' is, instead i want to get a value from the listitem that was clicked - which is actually being displayed in the view already!

    any pointers would be great!!

     

    Advertisement

  2. Normano

    Normano Lurker
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Apr 8, 2010

    Apr 8, 2010
    2
    0
    25
    You have probably already found the answer but
    change
    Code (Text):
    1. intent.putExtra("itemID",0);
    to
    Code (Text):
    1. intent.putExtra("itemID", String.valueOf(position+1));
    so item 1 will give 1, remove +1 and item 1 will give 0
    That should work.:)
     

Share This Page

Loading...