Is there a simple list widget in android that lets me select from a list without having to create an adapter?

StackOverflow https://stackoverflow.com/questions/23089620

  •  04-07-2023
  •  | 
  •  

Вопрос

I have a list, I want the user to select one. It's a string. Maybe even have an Object I can associate with it. Is there any way to do this without creating a subclass with an arrayadapter? I see tons of examples and they all seem overengineered for what must be the most basic list handling problem in the world. Is there no default simple list string handler built in? If there is, I can't find it. Help?

Это было полезно?

Решение

Is there no default simple list string handler built in?

ListView is a simple list string handler that's built in.

Is there any way to do this without creating a subclass with an arrayadapter?

You don't have to subclass ArrayAdapter to use it. Binding the data to ListView is one line of code:

final ListView list = ...;
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));

In your case, data would either be a List<String> or a String[].

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top