Hey Megha, Sorry if I wasn't clear - I know the concept might be a little muddied in the example... Basically the issue seems to be that since Spinner doesn't actually support the 'OnItemClickListener' (fires an exception according to docs) we're left to deal with the 'OnItemSelected' event. Since the selection model for the spinner dictates that an item selection event is fired every time it is selected (read - highlighted). This is creating difficulties for anyone who uses a callback based on the selection of an item in a dropdown list from a spinner. When the dropdown is expanded, a user might run up and down through items in the list - firing an event each time an item is highlighted.... what we really want is just the final event selection. (equivalent to what we would commonly think of as result from the 'OnClick' event).
Consider my app where I query a webservice based on a spinner selection - I don't want to open a URL input stream and parse a JSON object in my worker thread while a progress dialog spins for every highlighted item in the list... I just want to capture the user's final selection. I'm wondering if we can use the 'state_dropdown_showing' on the Spinner's View component to determine if it's expanded so that we can ignore intermediate selection events... Hopefully that's a little clearer? Thanks Todd On Apr 2, 6:33 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote: > Hi Todd, > > Its not clear to me what you are trying to do, I read twice through your > post, but I couldn't figure it out. > > Thanks, > Megha > > On Wed, Apr 2, 2008 at 1:57 PM, lee.t <[EMAIL PROTECTED]> wrote: > > > Seems there have been a lot of questions regarding the selection model > > for the spinner (ie - no OnItemClicked, only OnItemSelected listeners, > > making it difficult to use callbacks which respond to 'final' item > > selection and not every 'browsing' selection in between). Most > > proposed solutions to this involve catching key events etc... has > > anyone come up with anything better than this? > > > As I sit here (without my eclipse IDE, so I can't try it myself :( ) > > I'm wondering if it isn't possible to detect the state of the spinner > > (ie - expanded as drop-down, vs collapsed 'left-right/up-down' > > selection). I'm assuming we can do this by taking advantage of the > > 'state' methods available for the View class and the > > 'state_dropdown_showing' constant mentioned in issue 330 (are these > > applicable/supported in this instance?) > > > Presumably we might have something like this for a Spinner object > > named 's': > > > // s.setOnItemSelectedListener(new > > Spinner.OnItemSelectedListener(){ > > // public void onItemSelected(AdapterView parent, View > > v, int position, long id) { > > // int[] state = v.getDrawableState(); > > // for(int i=0; i<state.length; i++){ > > // if(state[i]==R.attr.stat_dropdown_showing){ > > // // just bail because we want to ignore > > this 'browsing' selection... > > // return; > > // } > > // } > > // // assuming that we're not showing a dropdown, > > do callback on fired selection > > // // (presumably this is a 'left-right/keyup- > > keydown' selection) > > // doCallback(); > > // } > > // > > // public void onNothingSelected(AdapterView arg0) { > > // // do nothing > > // } > > // }); > > > Has anybody tried this? I'd be curious to know if it might work... > > I'm assuming that there's a risk here of losing the selection we're > > actually trying to get while the dropdown is open since presumably the > > OnItemSelected event fires while the View's state has the drop-down > > showing, even for the final selection... but I think that's wouldn't > > be too difficult to overcome if the rest of it will work... > > > Any Android wizards out there who care to comment on the idea? Am I > > out in left field or does this have a chance of working? > > Suggestions welcome... > > > Thanks > > Todd --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new M5 SDK! http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---