I have a spinner widget in my activity which lets users pick a list name.
Normally, the function of the spinner is to switch between lists but for a couple of instances, I swap out the selection change listener to perform a different function with the same list of options. Once the selection has been made, the old listener is restored and life goes on.
This is a bad and buggy arrangement. Instead, I would like to have a function that just takes a selection listener and some other parameters and shows a popup list that's populated by the same cursor (or and identical cursor) as the spinner, without using the spinner itself.
Is there any way I can do this?
This is best example for popup details like spinner using AlertDialog and AlertDialog.Builder
Use
AlertDialog.Builder
and supply anAdapter
viasetAdapter()
that generates your rows.In your case, I would not use the same
Cursor
, as aCursor
has an intrinsic notion of the current row, and so messing with theCursor
while it is used by yourSpinnerAdapter
could screw up theSpinner
. Go with an identicalCursor
.If you are not limited by API level 11 then listPopupWindow is close to what you want.
You might want to use PopupMenu
see this example