Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RecyclerView focus orientation
import android.support.v7.widget.RecyclerView
fun RecyclerView.getViewByPosition(position: Int): View? {
return findViewHolderForAdapterPosition(position)?.itemView
}
fun RecyclerView.fetchViewAt(position: Int, callback: (View?) -> Unit) {
scrollToPosition(position)
post { callback(getViewByPosition(position)) }
}
fun RecyclerView.focusChildAtPosition(position: Int, success: (Boolean) -> Unit = {}) {
fetchViewAt(position) {
success(it?.requestFocus() == true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.