-2

Hi guys so I have this doubt. I've created an app that stores data in a SQLite and its displayed on a Listview in the Main Activity. What I'm trying to do is once I click one item from the list it should open an image from sd card. So my question is how can I use onClick here since I don't know the longitude of the list? And may I include the onclick for the list in the switch I've got?

UPDATED: I forgot to say that that I would like to open an image stored in the sdcard when I click a item of the list.

That's what I've got for now:

    Contact_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            String lat = cursor.getString(cursor.getColumnIndexOrThrow("lat"));
            Toast.makeText(getApplicationContext(), lat, Toast.LENGTH_SHORT).show();
        }
    });

All comments or suggestions are welcomed. Thanks!

PFUser
  • 13
  • 5
  • possible duplicate of [How to handle the click event in Listview in android?](http://stackoverflow.com/questions/17851687/how-to-handle-the-click-event-in-listview-in-android) – Dhaval Parmar Jul 04 '14 at 05:50

1 Answers1

1

Use setOnItemClickListener() method:

Contact_listview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1, final int selectedIndex, long arg3) {       
    }
);
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
PLP
  • 714
  • 3
  • 13
  • But the only I can get is the id of the selected item. Is there any way I could get the content of the item? – PFUser Jul 07 '14 at 17:04