0

I have created a spinner at the header of a listview. How do I add text into it? I would like to show the text in the spinnerText.

String[] spinnerText = { "Sort by date posted (latest to oldest)", "Sort by price (lowest to highest)"}; LayoutInflater inflater = LayoutInflater.from(this); View spinTop = inflater.inflate(R.layout.spin, null); getListView().addHeaderView(spinTop); 
2

2 Answers 2

1

You should try to use an ArrayAdapter like this :

spinTop.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, spinnerText)); 
Sign up to request clarification or add additional context in comments.

Comments

0

You have to use an ArrayAdapter<String> as follows:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,spinnerText); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinTop.setAdapter(adapter); 

Also you'll have to cast spinTop:

Spinner spinTop = (Spinner) inflater.inflate(R.layout.spin, null); 

2 Comments

Already cast the spinTop but i am having this error: The method setAdapter(ArrayAdapter<String>) is undefined for the type View
Declare spinTop as a Spinner, not as a View.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.