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