Answer the question
In order to leave comments, you need to log in
How to get listview item data?
We need to get data from the ListView (using the system simple_list_item_2 with two TextViews). What should I add to my code?
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object head = adapter.getItem(position); //насчёт типа переменной не уверен, но компилятор ожидал увидеть здесь Object
}
});
Answer the question
In order to leave comments, you need to log in
Well just cast
(Map<String, *что у вас там*>)adapter.getItem(position)
And pull out the key from the map. ListView is deprecated and not recommended. Use RecyclerView, and inside ViewHolder set listeners to the necessary elements and send events using EventBus. Inside the adapter, write a method that will return the desired element from the array. The position of the element is equal to the position of the object in the array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question