Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android listview get selected item

I am new to android, I have a code in which I have placed buttons in list view. My list is as..

Number | Name | ID (visibility = gone) | Level | button1 | button2 

Function is different in button 1 and button 2 case. I have applied listeners on buttons but when I try to get the ID from list it always shows me the last id.

How to know which button was clicked, name and id of related field.

I have placed buttons and listener on buttons in getView(...) function.

like image 856
AZ_ Avatar asked Dec 22 '10 12:12

AZ_


People also ask

How do I get the selected list of items?

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 );


1 Answers

final ListView lv = (ListView) findViewById(R.id.ListView01);  lv.setOnItemClickListener(new OnItemClickListener() {       public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {         String selectedFromList =(String) (lv.getItemAtPosition(myItemInt));        }                  }); 

I hope this fixes your problem.

like image 126
Adesara Avatar answered Oct 04 '22 11:10

Adesara