It's quite simple. I just want to add Strings
to a Spinner
without using the .xml
and without using the Resources
folder.
I used onCreateOptionsMenu(Menu menu)
, but I didn't find any solution to my problem.
I have seen How can I add items to a spinner in Android?, but it doesn't work in my case...
Here's my code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar3, menu);
setTitle("");
String[] arraySpinner = new String[] {
"1", "2", "3", "4", "5"
};
Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.array.spinner_values);
s.setAdapter(adapter);
return true;
}
Note: This code doesn't run since I need a type of layout, but I don't know what layout...