Android ListView and OnClickListener: how to get the selected item

I have a listView with some elements.

I would like to get the name (String) of the selected item from my onClickListener.

I know how to get the selected position, but how to find the row of this element?

Here is my click listener:

journalNames.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view,int position, long id) { }}); 

My View list is populated with some query from the database.

Thanks.

+8
android android-listview
source share
2 answers

What,

 journalNames.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view,int position, long id) { String selectedFromList = (journalNames.getItemAtPosition(position).getString()); }}); 
+17
source share

You can find it either in full view or on the parent. In eclipse just enter a view. and see what methods you get after input. (dot). I think this is the best.

 parent.getAdapter().getItem(position); 
+8
source share

All Articles