please help me in following =>
what is difference between getSelectedItemId
and getSelectedItemPosition
of spinner
please help me in following =>
what is difference between getSelectedItemId
and getSelectedItemPosition
of spinner
I know this is very old, but for future reference here is what I found:
getSelectedItemPosition()
works as you would expect and returns the position of the selected item in an array containing only the items. For example when the adapter is created with the following array data
["Alice", "Bob", "Carol", "Dave"]
and given Carol
would be currently selected, this method would return 2
, the index of Carol
in the array.
Now for the more interesting part, getSelectedItemId()
:
This method can be used when the spinner was set up with for example a SimpleCursorAdapter
, so the populated data is based on a cursor. This cursor enables you to have two columns, _id
and someValue
(the id column name must be _id, the second column can be called anything).
Given the following cursor
+-----+-------+
| _id | name |
+-----+-------+
| 55 | Alice |
| 67 | Bob |
| 72 | Carol |
| 84 | Dave |
+-----+-------+
and again given, that Carol
is selected, this method will return 72
, so the value of the selected rows '_id' column.
When the SpinnerAdapter is based on a "normal array", the id and position seem to be identical and both methods will return the same value.
I do not promise that this information is complete and 100% accurate, but is what I have found out through trial and error so far.
© 2022 - 2024 — McMap. All rights reserved.