Stay organized with collections
Save and categorize content based on your preferences.
AdapterView.OnItemSelectedListener
public
static
interface
AdapterView.OnItemSelectedListener
android.widget.AdapterView.OnItemSelectedListener
|
Interface definition for a callback to be invoked when
an item in this view has been selected.
Summary
Public methods |
abstract
void
|
onItemSelected(AdapterView<?> parent, View view, int position, long id)
Callback method to be invoked when an item in this view has been
selected.
|
abstract
void
|
onNothingSelected(AdapterView<?> parent)
Callback method to be invoked when the selection disappears from this
view.
|
Public methods
public abstract void onItemSelected (AdapterView<?> parent,
View view,
int position,
long id)
Callback method to be invoked when an item in this view has been
selected. This callback is invoked only when the newly selected
position is different from the previously selected position or if
there was no selected item.
Implementers can call getItemAtPosition(position) if they need to access the
data associated with the selected item.
Parameters |
parent |
AdapterView : The AdapterView where the selection happened |
view |
View : The view within the AdapterView that was clicked |
position |
int : The position of the view in the adapter |
id |
long : The row id of the item that is selected |
public abstract void onNothingSelected (AdapterView<?> parent)
Callback method to be invoked when the selection disappears from this
view. The selection can disappear for instance when touch is activated
or when the adapter becomes empty.
Parameters |
parent |
AdapterView : The AdapterView that now contains no selected item. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# AdapterView.OnItemSelectedListener\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nAdapterView.OnItemSelectedListener\n==================================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/widget/AdapterView.OnItemSelectedListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nAdapterView.OnItemSelectedListener\n`\n\n\n`\n\n\n`\n\n|---------------------------------------------------|\n| android.widget.AdapterView.OnItemSelectedListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInterface definition for a callback to be invoked when\nan item in this view has been selected.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onItemSelected](/reference/android/widget/AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView\u003c?\u003e,%20android.view.View,%20int,%20long))`(`[AdapterView](/reference/android/widget/AdapterView)`\u003c?\u003e parent, `[View](/reference/android/view/View)` view, int position, long id) ` \u003cbr /\u003e Callback method to be invoked when an item in this view has been selected. |\n| ` abstract void` | ` `[onNothingSelected](/reference/android/widget/AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView\u003c?\u003e))`(`[AdapterView](/reference/android/widget/AdapterView)`\u003c?\u003e parent) ` Callback method to be invoked when the selection disappears from this view. |\n\nPublic methods\n--------------\n\n### onItemSelected\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onItemSelected (AdapterView\u003c?\u003e parent, \n View view, \n int position, \n long id)\n```\n\n\u003cbr /\u003e\n\nCallback method to be invoked when an item in this view has been\nselected. This callback is invoked only when the newly selected\nposition is different from the previously selected position or if\nthere was no selected item.\nImplementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|--------------------------------------------------------------------|\n| `parent` | `AdapterView`: The AdapterView where the selection happened \u003cbr /\u003e |\n| `view` | `View`: The view within the AdapterView that was clicked \u003cbr /\u003e |\n| `position` | `int`: The position of the view in the adapter \u003cbr /\u003e |\n| `id` | `long`: The row id of the item that is selected \u003cbr /\u003e |\n\n### onNothingSelected\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onNothingSelected (AdapterView\u003c?\u003e parent)\n```\n\nCallback method to be invoked when the selection disappears from this\nview. The selection can disappear for instance when touch is activated\nor when the adapter becomes empty.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|---------------------------------------------------------------------------|\n| `parent` | `AdapterView`: The AdapterView that now contains no selected item. \u003cbr /\u003e |"]]