# ParkedOnlyOnClickListener

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/ParkedOnlyOnClickListener.java+class:androidx.car.app.model.ParkedOnlyOnClickListener) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
@CarProtocol
public final class ParkedOnlyOnClickListener implements OnClickListener
```

<br />

*** ** * ** ***

An `https://developer.android.com/reference/androidx/car/app/model/OnClickListener` that wraps another one and executes its `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener#onClick()` method only when the car is parked.

When the car is not parked, the handler won't be executed and the host will display a message to the user indicating that the action can only be used while parked.

Actions that direct the users to their phones must only execute while parked. This class should be used for wrapping any click listeners that invoke such actions.

Example:

```
builder.setOnClickListener(ParkedOnlyOnClickListener.create(
    () -> myClickAction()));
```

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener` | `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener#create(androidx.car.app.model.OnClickListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/OnClickListener listener)` Constructs a new instance of a `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener`. |
| `void` | `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener#onClick()()` Triggers the `https://developer.android.com/reference/androidx/car/app/model/OnClickListener#onClick()` method in the listener wrapped by this object. |

## Public methods

### create

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

```
public static @NonNull ParkedOnlyOnClickListener create(@NonNull OnClickListener listener)
```

Constructs a new instance of a `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener`.

Note that the listener relates to UI events and will be executed on the main thread using `https://developer.android.com/reference/android/os/Looper.html#getMainLooper()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `listener` is `null` |

### onClick

```
public void onClick()
```

Triggers the `https://developer.android.com/reference/androidx/car/app/model/OnClickListener#onClick()` method in the listener wrapped by this object.