Stay organized with collections
Save and categorize content based on your preferences.
OnItemSelectedListener
interface OnItemSelectedListener
Interface definition for a callback to be invoked when an item in this view has been selected.
Summary
Public methods |
abstract Unit |
Callback method to be invoked when an item in this view has been selected.
|
abstract Unit |
Callback method to be invoked when the selection disappears from this view.
|
Public methods
onItemSelected
abstract fun onItemSelected(
parent: AdapterView<*>!,
view: View!,
position: Int,
id: Long
): Unit
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 |
onNothingSelected
abstract fun onNothingSelected(parent: AdapterView<*>!): Unit
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# AdapterView.OnItemSelectedListener\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnItemSelectedListener\n======================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/widget/AdapterView.OnItemSelectedListener \"View this page in Java\") \n\n```\ninterface OnItemSelectedListener\n```\n\n|--------------------------------------------------------|\n| [android.widget.AdapterView.OnItemSelectedListener](#) |\n\nInterface definition for a callback to be invoked when an item in this view has been selected.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onItemSelected](#onItemSelected(android.widget.AdapterView,%20android.view.View,%20kotlin.Int,%20kotlin.Long))`(`parent:` `[AdapterView](/reference/kotlin/android/widget/AdapterView)\u003c*\u003e!`, `view:` `[View](../view/View.html#)!`, `position:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `id:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Callback method to be invoked when an item in this view has been selected. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onNothingSelected](#onNothingSelected(android.widget.AdapterView))`(`parent:` `[AdapterView](/reference/kotlin/android/widget/AdapterView)\u003c*\u003e!`)` 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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onItemSelected(\n parent: AdapterView\u003c*\u003e!, \n view: View!, \n position: Int, \n id: Long\n): Unit\n```\n\nCallback 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.\nImplementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.\n\n| Parameters ||\n|------------|-----------------------------------------------------------------------------------------------------------------------|\n| `parent` | [AdapterView](/reference/kotlin/android/widget/AdapterView)\\\u003c\\*\\\u003e!: The AdapterView where the selection happened |\n| `view` | [View](../view/View.html#)!: The view within the AdapterView that was clicked |\n| `position` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The position of the view in the adapter |\n| `id` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): The row id of the item that is selected |\n\n### onNothingSelected\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onNothingSelected(parent: AdapterView\u003c*\u003e!): Unit\n```\n\nCallback 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.\n\n| Parameters ||\n|----------|-------------------------------------------------------------------------------------------------------------------------|\n| `parent` | [AdapterView](/reference/kotlin/android/widget/AdapterView)\\\u003c\\*\\\u003e!: The AdapterView that now contains no selected item. |"]]