-
Notifications
You must be signed in to change notification settings - Fork 563
Does AdapterView deserve attention? #470
Comments
What would the extensions do? |
I'll just post method signature here. Later today or tomorrow prepare PR to be more precise and kick off detailed discussion. @Suppress("UNCHECKED_CAST")
inline fun <ITEM> AdapterView<*>.onItemClick(
crossinline onItemClick: (item: ITEM) -> Unit
) @Suppress("UNCHECKED_CAST")
inline fun <ITEM> AdapterView<*>.onItemLongClick(
crossinline onItemLongClick: (item: ITEM) -> Boolean
) inline fun AdapterView<*>.onItemSelected(
crossinline onNothingSelected: () -> Unit = {},
crossinline onItemSelected: (parent: AdapterView<*>?, view: View?, position: Int, id: Long) -> Unit
) @Suppress("UNCHECKED_CAST")
inline fun <ITEM> AdapterView<*>.onItemSelected(
crossinline onNothingSelected: () -> Unit = {},
crossinline onItemSelected: (item: ITEM) -> Unit
) Generally some sugar on the AdapterView setting click listeners ceremony. |
setOnItemSelectedListener can be shorten as
Then we can use this extension like this
|
Work in progres PR is ready #484. I need to finish some tests but most importantly I'm waiting for feedback on implementation. |
@sohailehmad please note that with default argument for onNothingSelected you still can use method without specifying both arguments and can invoke it like that:
I'd agree that onNothingSelected is rarely used but getting rid of of it completely as in your implementation proposition might not be the best options. Especially that we can have concise and general method that handle both arguments. |
PR updated and ready for review. |
I was thinking about adding some AdapterView extentions. Some listeners setting extentions first for those:
setOnItemClickListener
setOnItemLongClickListener
setOnItemSelectedListener
I'm using them for Spinners in my project atm. Should I prepare PR?
The text was updated successfully, but these errors were encountered: