Reputation: 41
I am trying to get the selected value out of a single choice list view and it won't let me use the setOnItemClickListener
any ideas?
final ListView lv = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, values);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
String selectedFromList = (lv.getItemAtPosition(myItemInt));
}
}
Upvotes: 2
Views: 1624
Reputation: 9283
you don't need to bind the "onItemClickListener", just use "getCheckedItemPosition" and you can get the checked position. then get the selected item from your data source.
Upvotes: 1
Reputation: 158
modify like this: String selectedFromList = (String) (lv.getItemAtPosition(myItemInt));
Upvotes: 1