Anyone? I really think it's not that complicated? running out of time. anybody please?
thanks! On Jul 1, 4:24 pm, Georgy <[email protected]> wrote: > issue still unresolved if someone is having the same issue. > > On Jun 22, 1:46 pm, Georgy <[email protected]> wrote: > > > > > anyone?? > > > On Jun 21, 12:31 pm, Georgy <[email protected]> wrote: > > > > Hello, > > > > I am trying to populate a spinner depending on another spinner's > > > selected item, my code is the following: > > > > @Override > > > public void onCreate(Bundle icicle) { > > > super.onCreate(icicle); > > > setContentView(R.layout.main); > > > > final Dbadapter db = new Dbadapter(this); // This creates an > > > instance of the database in this class > > > > // Initialization of the 1st spinner > > > final Spinner s = (Spinner) findViewById(R.id.spinner); > > > ArrayAdapter adapter = ArrayAdapter.createFromResource( > > > this, R.array.universities, > > > android.R.layout.simple_spinner_item); > > > adapter.setDropDownViewResource > > > (android.R.layout.simple_spinner_dropdown_item); > > > s.setAdapter(adapter); > > > > // Initialization of the 2nd spinner > > > String[] array = {"Select Building Here"}; > > > final Spinner s2 = (Spinner) findViewById(R.id.spinner2); > > > db.open(); > > > final Cursor cur = db.getAllTitles(); > > > String[] columns = new String[]{"building","locode"}; > > > SimpleCursorAdapter cadapter = new > > > SimpleCursorAdapter(this, > > > android.R.layout.simple_spinner_item, cur, > > > columns, new int[] {android.R.id.text1}); > > > cadapter.setDropDownViewResource > > > (android.R.layout.simple_spinner_dropdown_item); > > > s2.setAdapter(cadapter); > > > > // When user selects a university > > > s.setOnItemSelectedListener(new OnItemSelectedListener() { > > > > @Override > > > public void onItemSelected(AdapterView<?> arg0, > > > View arg1, > > > int arg2, long arg3) { > > > //Get the selected university > > > String selectedItemString = (String) > > > s.getSelectedItem(); > > > System.out.println > > > ("Uni: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+selectedItemString); > > > > if(selectedItemString .equals("Old Dominion > > > University")) > > > { > > > oduspinner(); > > > > } > > > > else > > > { > > > nospinner(); > > > } > > > > } > > > > @Override > > > public void onNothingSelected(AdapterView<?> > > > arg0) { > > > // TODO Auto-generated method stub > > > } > > > > }); > > > > // When user selects a university > > > s2.setOnItemSelectedListener(new OnItemSelectedListener() { > > > > @Override > > > public void onItemSelected(AdapterView<?> arg0, > > > View arg1, > > > int arg2, long arg3) { > > > > System.out.println("Entered 2nd > > > spinner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); > > > String selected= (String) > > > s2.getSelectedItem(); > > > System.out.println("Entered 2nd > > > spinner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+ selected); > > > > } > > > > @Override > > > public void onNothingSelected(AdapterView<?> > > > arg0) { > > > // TODO Auto-generated method stub > > > > } > > > > }); > > > > } > > > > what is intriguing me is that the first spinner onitemselection works > > > perfectly ( I can see the values in LogCat) then when I change > > > selection of the 2nd spinner I am gettging an error on this line: > > > String selected= (String) s2.getSelectedItem(); So the compiler gets > > > insisde then onItemSelected function of the 2nd spinner but throws an > > > Handler exceltion on s2.getSelectedItem() > > > > why? it works perfectly for the 1st spinner. > > > > please help, > > > thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

