java - Android Dynamic Spinner Update -


I am working with Android and Spinner and I need some help. I have a class that creates two spinners and one button. The first spinner is for my class, my second is for my sub-category. What I am trying to do is dynamically updating the second spinner (spinner 2). I am trying to use adapter2.clear (), but that crashes Android, "Error with" activity componentUnable unable to start unsupported operation "

Here my code is:

  public class Maikls the Maybs class {Int class; Int sub_category; ArrayAdapter & LT; string & gt; adapter2; / ** activity was called upon for the first time. * / @Override Public Zero OnCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.quizes); // Category H Denied final String [] items 1 = new String [] { "one", "two", "three"}; Last spinner spinner 1 = (Spinner) searching for Vivibiaiaidi (RID spinner 1); ArrayAdapter & LT; string & gt; adapter 1 = new Arre adapter & lt; string & gt; (it, android.R.layout.simple_spinner_item, items1); adapter1.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter (adapter1); // SUBCATEGORY INFO Last String [] Item 2 = New String [] {"SOne", "STwo", "SThree"}; Final Spinner Spinner 2 = (Spinner) Find VVBIID (RID Spinner 2); Adapter 2 = New Array Adapter & lt; String & gt; (This, android.R.layout.simple_spinner_item, items2); Adapter2.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); Spinner2.setAdapter (adapter2); // Capture our button from the layout button button = (button) findViewById (R.id.button1); // button click onclick listener button .setOnClickListener (new OnClickListener () {public void onClick (View v) {// is something that happens when you click the button startActivity (new Intent (MyClass.This, GoToOtherClass .class));}}); // SELECTOR CONTROL FOR SPINNER1 {CATEGORY} spinner1.setOnItemSelectedListener (new Onitmslekted Listnr () {@Override public items selected to zero (Adeptrwu & lt ;? & Gt; RG 0, AGR 1 See, Intret arg2, long RG 3) {MyClass Override public zero on .this.category = spinner1.getSelectedItemPosition (); // other stuff} @NoSelected (adapter view   

I understand. () /. Add () methods, but any time I try to crush () / add () my program, what I need to do is fix things so I can change spinner2 content for my sub-category list ? Any advice will help, because I have spent several hours such as:

Object T = Adapter 2. Gatitim (0); Spinner2.remove (string) t);

or adapter2.clear () and some other tricks and I have not left any other suggestions I'm still learning Android. I tried to see StackHowflow and some other posts here on Google but it was not sure how their thoughts worked. >

After you change the contents of the second spinner, you must call adapter2.notifyDataSetChanged () . Without that call, the UI will not update with the spinner's new material, and you may also have a problem referencing things that are no longer present.

Comments