Android Wing of mucchin | Related Spinner



The easiest way when you want to make a dynamic choice of Spinner


An easy way If you want to change dynamically the choice of Spinner is?

The easiest way is good for a fixed choice of Spinner is static, we have introduced earlier.
Simplest usage of Spinner
So,,, for example, place a Spinner in this way if,
Spinner also want to change the dynamic choices, such as in the layout you want to place the same!
I will introduce the way, if that.


A basic description is omitted.
But only one case, can be achieved by methods such as the following.

private void setSpinner (Spinner spinner, String [] arr) {
ArrayAdapter adapter =
new ArrayAdapter
(This, android.R.layout.simple_spinner_item, arr);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter (adapter);
}


The first argument is an instance of the Spinner you want to set the choices.
Second argument is an array of type String that contains the string of choices that you want to configure.

Spinner of the first argument, it is common to pass or has been taken in Spinner () findViewById probably.
Choices of how to generate the second argument, so vary according to each application, does not say anything, so that it can be used for general purposes, was introduced as a method such as the above sample.

As two points.
The first is that the second argument of the constructor when generating an instance of ArrayAdapter, it sets up the following.
android.R.layout.simple_spinner_item

The second is that point in the method adapter.setDropDownViewResource (), it sets up the following.
android.R.layout.simple_spinner_dropdown_item

This simplest usage of Spinner Spinner Spinner of the same layout as such was introduced in is completed.

2 A 2 page one of two