Thanks, though I wasn't confused about which Listener I needed to set
in order to respond to a selection from a user.
Nor how to ignore the initial selection using a switch in that
Listener (though that is something that is also annoying).
I was hoping to use those Listeners to switch from a null Adapater to
my real Adapter prior to displaying the DropDownView so it would
1) only show the items that are truly available for selection
2) not show any selected item prior to DropDownView.
It seems strange that a ListView can have no items selected via
#setSelection(-1), but a Spinner cannot.
It all hinges on the code in AbsSpinner#setAdapter
if (mAdapter != null) {
...
mItemCount = mAdapater.getCount();
int position = mItemCount > 0 ? 0 : INVALID_POSITION;
setSelectedPositionInt(position);
setNextSelectedPositionInt(position);
...
}
which selects the first element in the Adapter when the Adapter is
set. But if it was
if (mAdapter != null) {
...
mItemCount = mAdapater.getCount();
int position = INVALID_POSITION;
setSelectedPositionInt(position);
setNextSelectedPositionInt(position);
...
}
then initial selection of the Spinner would be configurable instead of
always being the first element.
On Aug 22, 5:21 pm, TreKing <[email protected]> wrote:
> On Sat, Aug 21, 2010 at 5:33 PM, William Ferguson <william.ferguson.au@
>
> gmail.com> wrote:
> > I don't want to add an empty/blank item at the head of my list of
> > items because that means that it shows as an avalaible selection in
> > the DropDownView and looks pretty lame.
>
> This is pretty common practice. There's really nothing wrong with doing this
> (granted, I'm biased, as this is what I do, and I don't think it's "pretty
> lame")
>
> > And if a selection is made I want it to be a valid one.
>
> It's trivial to ignore the initial selection.
>
> > but spinner#setOnClickListener throw a
> > RuntimeException saying "You probably want to use
> > #setOnItemClickListener instead". And trying to use
> > #setOnItemClickListener throws a RuntimeException saying it is not
> > valid for a Spinner.
>
> Yeah, those errors aren't very helpful. You're looking for
> setOnItem*SELECTED*Listener. Try that,
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
--
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