What i want to do is to add something in a spinner by clicking on it and then click in a "add option" tha appears in the spinner. I am new to android development. Can somebody help?
Thanks
You can create an adapter (for example, an ArrayAdapter) and then bind it to your spinner using the Spinner.setAdapter()
method.
After you override the Adapter.onItemSelected()
method in your onItemSelectedListener
, you can use a function like this (if you've implemented your onItemSelectedListener
within the same class that you've declared your adapter called arrayAdapter
):
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if (parent.getItemAtPosition(pos).toString().equals("Add Item")) {
arrayAdapter.add(new object()); //object is what your array contains
}
}
Look at the spinner tutorial for the in-between steps.
For an example of dynamically adding items to a Spinner, take a look at Populate Spinner dynamically in android from edit text
Other than this, what have you got so far? Where specifically are you stuck?