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
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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[].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top