# OnChildViewHolderSelectedListener

Artifact: [androidx.leanback:leanback-grid](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/OnChildViewHolderSelectedListener.java+class:androidx.leanback.widget.OnChildViewHolderSelectedListener) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.0.0)

*** ** * ** ***


```
public abstract class OnChildViewHolderSelectedListener
```

<br />

*** ** * ** ***

Interface for receiving notification when a child of this ViewGroup has been selected. There are two methods:

- {link `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#onChildViewHolderSelected(androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.ViewHolder,int,int)`} is called when the view holder is about to be selected. The listener could change size of the view holder in this callback.
- {link `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#onChildViewHolderSelectedAndPositioned(androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.ViewHolder,int,int)` is called when view holder has been selected and laid out in RecyclerView.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#OnChildViewHolderSelectedListener()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#onChildViewHolderSelected(androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.ViewHolder,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder child, int position, int subposition )` Callback method to be invoked when a child of this ViewGroup has been selected. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#onChildViewHolderSelectedAndPositioned(androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.ViewHolder,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder child, int position, int subposition )` Callback method to be invoked when a child of this ViewGroup has been selected and positioned. |

## Public constructors

### OnChildViewHolderSelectedListener

Added in 1.0.0

```
public OnChildViewHolderSelectedListener()
```

## Public methods

### onChildViewHolderSelected

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.0.0)

```
public void onChildViewHolderSelected(
    @NonNull RecyclerView parent,
    @Nullable RecyclerView.ViewHolder child,
    int position,
    int subposition
)
```

Callback method to be invoked when a child of this ViewGroup has been selected. Listener might change the size of the child and the position of the child is not finalized. To get the final layout position of child, override `https://developer.android.com/reference/androidx/leanback/widget/OnChildViewHolderSelectedListener#onChildViewHolderSelectedAndPositioned(androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.ViewHolder,int,int)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | The RecyclerView where the selection happened. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder child` | The ViewHolder within the RecyclerView that is selected, or null if no view is selected. |
| `int position` | The position of the view in the adapter, or NO_POSITION if no view is selected. |
| `int subposition` | The index of which `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef` being used, 0 if there is no ItemAlignmentDef defined for the item. |

### onChildViewHolderSelectedAndPositioned

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.0.0)

```
public void onChildViewHolderSelectedAndPositioned(
    @NonNull RecyclerView parent,
    @Nullable RecyclerView.ViewHolder child,
    int position,
    int subposition
)
```

Callback method to be invoked when a child of this ViewGroup has been selected and positioned.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | The RecyclerView where the selection happened. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder child` | The ViewHolder within the RecyclerView that is selected, or null if no view is selected. |
| `int position` | The position of the view in the adapter, or NO_POSITION if no view is selected. |
| `int subposition` | The index of which `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef` being used, 0 if there is no ItemAlignmentDef defined for the item. |