java - Enable a currently disabled Spinner in Android -
I was fooling around with Android and my Java knowledge was best (for example, I'm upset with this fact That it allows inline squares !?).
My question is as follows:
I have a layout where there are three dropdown menus, I initialize all three of them in the form ().
The first takes its value from a string-array; Second, however, depends on the first choice and the third depends on the choice of the other in turn!
I have some string-arrays for the second spinner, but I think that what would be the right way to implement the list of successively capable spinners, I just wanted to hack into it and work it I am trying, but I do not want to run the risk of being faulty and unstable.
For example, my case is like I have
in my resources I have an arrays.xml like:
In the onCreate method I started three:
@Override Public Zero OnCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); SetContentView (R.layout.main); Spinner spinner 1 = (spinner) Find VVBIID (RID planetpinner); Spinner Spinner 2 = (Spinner) Find VVBiID (RID. Moonspinner); Spinner Spinner 3 = (Spinner) Find VVBIID (RID Crater Spinner); Spinner2.setEnabled (false); Spinner3.setEnabled (false); ArrayAdapter adapter1 = ArrayAdapter.createFromResource (This, R.array.planets, android.R.layout.simple_spinary_item); Adapter1.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); Spinner1.setAdapter (adapter1); Spinner1.setOnItemSelectedListener (New MyOnPlanetSelectedListener ()); }
is my listener class
public class MyOnPlanetSelectedListener applies OnItemSelectedListener {Public Zero onItemSelected (AdapterView & LT;? & Gt; Parents, View View , Int status, long id) {Toast.makeText (parent.getContext ()), "Planet" + parent.getItemAtPosition (POS) .toString (), Toast.LENGTH_LONG) .show (); } Nothing at public zero (adapterviewer parent) {// do nothing}}
So there it is. My question is, how and how to implement the listeners for continuous spinners so that they can be enabled after the first selection. My first estimate is:
Public class MyOnPlanetSelectedListener applies OnItemSelectedListener {Public Zero onItemSelected (AdapterView << Parents, View View, Status Int, Long ID?) {Toast.makeText (Parent.getContext ()), "Planets" + Parents. Gate IT status (pause) .toString (), Toast. LNNGH_LOG). Show (); Spinner2.setEnabled (true); } Nothing at public zero (adapterviewer parent) {// do nothing}}
But obviously this is wrong since spinner2 is not explained here.
Then, on the basis of spinners continuously, a string array for your adapter should be selected. Before selecting spinners
Thank you very much for your help.
Create spinner 1, 2 and 3 members of the class (activity) Then compare the for
onprinted > Code> onItemSelected >>> This is simple by event logic.
private spinner spinner 1;
view
against the ultimate
(see == this.spinner1) {// Spinner 1 // came out of the event, create a new adapter, repeat the new adapter to the spinner 2} and if (see == this.spinner2) {// event came from spinner 2}
Comments
Post a Comment