I have a listView vith some items.
I would like to get from my onClickListener the name (String) of the selected item.
I know how to get the selected position but how to find the String of this element?
Here is my on click listener:
journalNames.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
}});
My listView is populated with some query from the database.
Thank you.
To get which item was selected, there is a method of the ListView called getItemAtPosition. Add this line to your OnItemClick method: String itemValue = (String) theListView. getItemAtPosition( position );
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
What about,
journalNames.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
String selectedFromList = (journalNames.getItemAtPosition(position).getString());
}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With