Spinner Widgets and On..Listener Callbacks

Put your problem here if it does not fit any of the other categories.

Spinner Widgets and On..Listener Callbacks

Postby TokenUser » Thu Dec 13, 2007 3:13 pm

I have a basic form layout that relies upon a spinner - I originally had a button layout, but that became unweildy as more options were added. The UI is implemented just fine, reads in the options to populate the spinner, adds in the drop list functionality.

It looks great ... but I am a little confused about the callback implementation for a listener that will tell me WHAT the user has selected. I could just wait until the user clicks the "Next>" button I implemented, but the intent of the spinner is to dynamically change the UI based on the user feedback.

Intuitively, I feel it should be OnItemClickListener, but according to the docs, "A spinner does not support item click events". I also considered using "checkSelectionChanged()" but that is not something I can implement as part of a listener, and would be fine if I was just reading an opion on a "Next>" button click. So, currently I am dead in the water.

Can anyone share a code stub that will allow me to read the item selected in the Spinner?
TokenUser
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 13, 2007 3:02 pm
Location: Lost in States [NC, USA]

Top

Postby plusminus » Thu Dec 13, 2007 3:21 pm

Hello TokenUser,

is this what you were searching for :?:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Spinner sp = new Spinner(this);
  2.  
  3.         sp.setOnItemSelectedListener(new OnItemSelectedListener(){
  4.  
  5.                         @Override
  6.  
  7.                         public void onItemSelected(AdapterView parent, View v,
  8.  
  9.                                         int position, long id) {
  10.  
  11.                                
  12.  
  13.                         }
  14.  
  15.  
  16.  
  17.                         @Override
  18.  
  19.                         public void onNothingSelected(AdapterView arg0) {
  20.  
  21.                                
  22.  
  23.                         }
  24.  
  25.         });
  26.  
  27.         this.setContentView(sp);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby TokenUser » Thu Dec 13, 2007 4:17 pm

Thanks for the quick response.

I was trying to do something like this earlier, but it was not working.

Why? Because in refactoring my code I had duplicated my declaration of the Spinner inside a method - so it was local to the method. This had the effect that when I tried to manipulate the spiiner outside the method, I was not working with the correctly initialised object.

I now have another error, but I suspect that your solution was what I needed - in conjunction with a clear head and a more critical look at my code.

====[Edit]====
OK - all fixed. That was exactly what was needed. It appears that my error was introduced during the refactoring.

Hope I can repay the favour with responses to other peoples questions in the forums.
TokenUser
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 13, 2007 3:02 pm
Location: Lost in States [NC, USA]

Postby plusminus » Thu Dec 13, 2007 4:41 pm

TokenUser wrote:Thanks for the quick response.

...
====[Edit]====
OK - all fixed. That was exactly what was needed. It appears that my error was introduced during the refactoring.

Hope I can repay the favour with responses to other peoples questions in the forums.


I'll take you up on that :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests