# ListPopupWindow

Artifact: [androidx.appcompat:appcompat](https://developer.android.com/jetpack/androidx/releases/appcompat) [View Source](https://cs.android.com/search?q=file:androidx/appcompat/widget/ListPopupWindow.java+class:androidx.appcompat.widget.ListPopupWindow) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

*** ** * ** ***


```
public class ListPopupWindow
```

<br />

*** ** * ** ***

Static library support version of the framework's `https://developer.android.com/reference/android/widget/ListPopupWindow.html`. Used to write apps that run on platforms prior to Android L. When running on Android L or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/ListPopupWindow.html` |   |

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_FROM_FOCUSABLE() = 0` Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: the requirements for the input method should be based on the focusability of the popup. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NEEDED() = 1` Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: this popup always needs to work with an input method, regardless of whether it is focusable. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NOT_NEEDED() = 2` Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: this popup never needs to work with an input method, regardless of whether it is focusable. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#MATCH_PARENT() = -1` Alias for `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT`. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_ABOVE() = 0` The provided prompt view should appear above list content. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_BELOW() = 1` The provided prompt view should appear below list content. |
| `static final int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#WRAP_CONTENT() = -2` Alias for `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#ListPopupWindow(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Create a new, empty popup window capable of displaying items from a ListAdapter. |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#ListPopupWindow(android.content.Context,android.util.AttributeSet)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs)` Create a new, empty popup window capable of displaying items from a ListAdapter. |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#ListPopupWindow(android.content.Context,android.util.AttributeSet,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs, @https://developer.android.com/reference/androidx/annotation/AttrRes int defStyleAttr )` Create a new, empty popup window capable of displaying items from a ListAdapter. |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#ListPopupWindow(android.content.Context,android.util.AttributeSet,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs, @https://developer.android.com/reference/androidx/annotation/AttrRes int defStyleAttr, @https://developer.android.com/reference/androidx/annotation/StyleRes int defStyleRes )` Create a new, empty popup window capable of displaying items from a ListAdapter. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#clearListSelection()()` Clear any current list selection. |
| `https://developer.android.com/reference/android/view/View.OnTouchListener.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#createDragToOpenListener(android.view.View)(https://developer.android.com/reference/android/view/View.html src)` Returns an `https://developer.android.com/reference/android/view/View.OnTouchListener.html` that can be added to the source view to implement drag-to-open behavior. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#dismiss()()` Dismiss the popup window. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getAnchorView()()` Returns the view that will be used to anchor this popup. |
| `@https://developer.android.com/reference/androidx/annotation/StyleRes int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getAnimationStyle()()` Returns the animation style that will be used when the popup window is shown or dismissed. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getBackground()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getEpicenterBounds()()` Return custom anchor-relative bounds of the popup's transition epicenter |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getHeight()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getHorizontalOffset()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getInputMethodMode()()` Return the current value in `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/ListView.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getListView()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getPromptPosition()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSelectedItem()()` |
| `long` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSelectedItemId()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSelectedItemPosition()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSelectedView()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSoftInputMode()()` Returns the current value in `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setSoftInputMode(int)`. |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getVerticalOffset()()` |
| `int` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getWidth()()` |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isInputMethodNotNeeded()()` |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isModal()()` Returns whether the popup window will be modal when shown. |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()()` |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#onKeyDown(int,android.view.KeyEvent)(int keyCode, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event)` Filter key down events. |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#onKeyPreIme(int,android.view.KeyEvent)(int keyCode, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event)` Filter pre-IME key events. |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#onKeyUp(int,android.view.KeyEvent)(int keyCode, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event)` Filter key up events. |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#performItemClick(int)(int position)` Perform an item click operation on the specified list adapter position. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#postShow()()` Post a `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#show()` call to the UI thread. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setAdapter(android.widget.ListAdapter)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/ListAdapter.html adapter)` Sets the adapter that provides the data and the views to represent the data in this popup window. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setAnchorView(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html anchor)` Sets the popup's anchor view. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setAnimationStyle(int)(@https://developer.android.com/reference/androidx/annotation/StyleRes int animationStyle)` Set an animation style to use when the popup window is shown or dismissed. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setBackgroundDrawable(android.graphics.drawable.Drawable)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html d)` Sets a drawable to be the background for the popup window. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setContentWidth(int)(int width)` Sets the width of the popup window by the size of its content. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setDropDownGravity(int)(int gravity)` Set the gravity of the dropdown list. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setEpicenterBounds(android.graphics.Rect)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Rect.html bounds)` Specifies the custom anchor-relative bounds of the popup's transition epicenter. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setHeight(int)(int height)` Sets the height of the popup window in pixels. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setHorizontalOffset(int)(int offset)` Set the horizontal offset of this popup from its anchor view in pixels. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)(int mode)` Control how the popup operates with an input method: one of `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_FROM_FOCUSABLE()`, `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NEEDED()`, or `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NOT_NEEDED()`. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setListSelector(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable.html selector)` Sets a drawable to use as the list item selector. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setModal(boolean)(boolean modal)` Set whether this window should be modal when shown. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setOnDismissListener(android.widget.PopupWindow.OnDismissListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/PopupWindow.OnDismissListener.html listener)` Set a listener to receive a callback when the popup is dismissed. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html clickListener )` Sets a listener to receive events when a list item is clicked. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/AdapterView.OnItemSelectedListener.html selectedListener )` Sets a listener to receive events when a list item is selected. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptPosition(int)(int position)` Set where the optional prompt view should appear. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptView(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html prompt)` Set a view to act as a user prompt for this popup window. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setSelection(int)(int position)` Set the selected position of the list. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setSoftInputMode(int)(int mode)` Sets the operating mode for the soft input area. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setVerticalOffset(int)(int offset)` Set the vertical offset of this popup from its anchor view in pixels. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setWidth(int)(int width)` Sets the width of the popup window in pixels. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setWindowLayoutType(int)(int layoutType)` Set the layout type for this popup window. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#show()()` Show the popup list. |

## Constants

### INPUT_METHOD_FROM_FOCUSABLE

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

```
public static final int INPUT_METHOD_FROM_FOCUSABLE = 0
```

Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: the requirements for the input method should be based on the focusability of the popup. That is if it is focusable than it needs to work with the input method, else it doesn't.

### INPUT_METHOD_NEEDED

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

```
public static final int INPUT_METHOD_NEEDED = 1
```

Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: this popup always needs to work with an input method, regardless of whether it is focusable. This means that it will always be displayed so that the user can also operate the input method while it is shown.

### INPUT_METHOD_NOT_NEEDED

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

```
public static final int INPUT_METHOD_NOT_NEEDED = 2
```

Mode for `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`: this popup never needs to work with an input method, regardless of whether it is focusable. This means that it will always be displayed to use as much space on the screen as needed, regardless of whether this covers the input method.

### MATCH_PARENT

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

```
public static final int MATCH_PARENT = -1
```

Alias for `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT`. If used to specify a popup width, the popup will match the width of the anchor view. If used to specify a popup height, the popup will fill available space.

### POSITION_PROMPT_ABOVE

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

```
public static final int POSITION_PROMPT_ABOVE = 0
```

The provided prompt view should appear above list content.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptPosition(int)` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getPromptPosition()` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptView(android.view.View)` |   |

### POSITION_PROMPT_BELOW

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

```
public static final int POSITION_PROMPT_BELOW = 1
```

The provided prompt view should appear below list content.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptPosition(int)` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getPromptPosition()` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptView(android.view.View)` |   |

### WRAP_CONTENT

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

```
public static final int WRAP_CONTENT = -2
```

Alias for `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT`. If used to specify a popup width, the popup will use the width of its content.

## Public constructors

### ListPopupWindow

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

```
public ListPopupWindow(@NonNull Context context)
```

Create a new, empty popup window capable of displaying items from a ListAdapter. Backgrounds should be set using `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setBackgroundDrawable(android.graphics.drawable.Drawable)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context used for contained views. |

### ListPopupWindow

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

```
public ListPopupWindow(@NonNull Context context, @Nullable AttributeSet attrs)
```

Create a new, empty popup window capable of displaying items from a ListAdapter. Backgrounds should be set using `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setBackgroundDrawable(android.graphics.drawable.Drawable)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context used for contained views. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs` | Attributes from inflating parent views used to style the popup. |

### ListPopupWindow

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

```
public ListPopupWindow(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    @AttrRes int defStyleAttr
)
```

Create a new, empty popup window capable of displaying items from a ListAdapter. Backgrounds should be set using `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setBackgroundDrawable(android.graphics.drawable.Drawable)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context used for contained views. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs` | Attributes from inflating parent views used to style the popup. |
| `@https://developer.android.com/reference/androidx/annotation/AttrRes int defStyleAttr` | Default style attribute to use for popup content. |

### ListPopupWindow

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

```
public ListPopupWindow(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes
)
```

Create a new, empty popup window capable of displaying items from a ListAdapter. Backgrounds should be set using `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setBackgroundDrawable(android.graphics.drawable.Drawable)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context used for contained views. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/AttributeSet.html attrs` | Attributes from inflating parent views used to style the popup. |
| `@https://developer.android.com/reference/androidx/annotation/AttrRes int defStyleAttr` | Style attribute to read for default styling of popup content. |
| `@https://developer.android.com/reference/androidx/annotation/StyleRes int defStyleRes` | Style resource ID to use for default styling of popup content. |

## Public methods

### clearListSelection

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

```
public void clearListSelection()
```

Clear any current list selection. Only valid when `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `true`.

### createDragToOpenListener

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

```
public View.OnTouchListener createDragToOpenListener(View src)
```

Returns an `https://developer.android.com/reference/android/view/View.OnTouchListener.html` that can be added to the source view to implement drag-to-open behavior. Generally, the source view should be the same view that was passed to `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setAnchorView(android.view.View)`.

When the listener is set on a view, touching that view and dragging outside of its bounds will open the popup window. Lifting will select the currently touched list item.

Example usage:

```
ListPopupWindow myPopup = new ListPopupWindow(context);
myPopup.setAnchor(myAnchor);
OnTouchListener dragListener = myPopup.createDragToOpenListener(myAnchor);
myAnchor.setOnTouchListener(dragListener);
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html src` | the view on which the resulting listener will be set |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/View.OnTouchListener.html` | a touch listener that controls drag-to-open behavior |

### dismiss

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

```
public void dismiss()
```

Dismiss the popup window.

### getAnchorView

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

```
public @Nullable View getAnchorView()
```

Returns the view that will be used to anchor this popup.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html` | The popup's anchor view |

### getAnimationStyle

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

```
public @StyleRes int getAnimationStyle()
```

Returns the animation style that will be used when the popup window is shown or dismissed.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/StyleRes int` | Animation style that will be used. |

### getBackground

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

```
public @Nullable Drawable getBackground()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | The background drawable for the popup window. |

### getEpicenterBounds

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

```
public @Nullable Rect getEpicenterBounds()
```

Return custom anchor-relative bounds of the popup's transition epicenter

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Rect.html` | anchor-relative bounds, or @`null` if not set |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setEpicenterBounds(android.graphics.Rect)` |   |

### getHeight

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

```
public int getHeight()
```

| Returns |
|---|---|
| `int` | The height of the popup window in pixels. |

### getHorizontalOffset

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

```
public int getHorizontalOffset()
```

| Returns |
|---|---|
| `int` | The horizontal offset of the popup from its anchor in pixels. |

### getInputMethodMode

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

```
public int getInputMethodMode()
```

Return the current value in `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setInputMethodMode(int)` |   |

### getListView

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

```
public @Nullable ListView getListView()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/ListView.html` | The `https://developer.android.com/reference/android/widget/ListView.html` displayed within the popup window. Only valid when `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `true`. |

### getPromptPosition

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

```
public int getPromptPosition()
```

| Returns |
|---|---|
| `int` | Where the optional prompt view should appear. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_ABOVE()` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_BELOW()` |   |

### getSelectedItem

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

```
public @Nullable Object getSelectedItem()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | The currently selected item or null if the popup is not showing. |

### getSelectedItemId

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

```
public long getSelectedItemId()
```

| Returns |
|---|---|
| `long` | The ID of the currently selected item or `https://developer.android.com/reference/android/widget/AdapterView.html#INVALID_ROW_ID` if `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `false`. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/AdapterView.html#getSelectedItemId()` |   |

### getSelectedItemPosition

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

```
public int getSelectedItemPosition()
```

| Returns |
|---|---|
| `int` | The position of the currently selected item or `https://developer.android.com/reference/android/widget/AdapterView.html#INVALID_POSITION` if `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `false`. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/AdapterView.html#getSelectedItemPosition()` |   |

### getSelectedView

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

```
public @Nullable View getSelectedView()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html` | The View for the currently selected item or null if `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `false`. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/AbsListView.html#getSelectedView()` |   |

### getSoftInputMode

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

```
public int getSoftInputMode()
```

Returns the current value in `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setSoftInputMode(int)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setSoftInputMode(int)` |   |
| `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#softInputMode` |   |

### getVerticalOffset

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

```
public int getVerticalOffset()
```

| Returns |
|---|---|
| `int` | The vertical offset of the popup from its anchor in pixels. |

### getWidth

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

```
public int getWidth()
```

| Returns |
|---|---|
| `int` | The width of the popup window in pixels. |

### isInputMethodNotNeeded

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

```
public boolean isInputMethodNotNeeded()
```

| Returns |
|---|---|
| `boolean` | `true` if this popup is configured to assume the user does not need to interact with the IME while it is showing, `false` otherwise. |

### isModal

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

```
public boolean isModal()
```

Returns whether the popup window will be modal when shown.

| Returns |
|---|---|
| `boolean` | `true` if the popup window will be modal, `false` otherwise. |

### isShowing

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

```
public boolean isShowing()
```

| Returns |
|---|---|
| `boolean` | `true` if the popup is currently showing, `false` otherwise. |

### onKeyDown

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

```
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event)
```

Filter key down events. By forwarding key down events to this function, views using non-modal ListPopupWindow can have it handle key selection of items.

| Parameters |
|---|---|
| `int keyCode` | keyCode param passed to the host view's onKeyDown |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event` | event param passed to the host view's onKeyDown |

| Returns |
|---|---|
| `boolean` | true if the event was handled, false if it was ignored. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setModal(boolean)` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#onKeyUp(int,android.view.KeyEvent)` |   |

### onKeyPreIme

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

```
public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event)
```

Filter pre-IME key events. By forwarding `https://developer.android.com/reference/android/view/View.html#onKeyPreIme(int, android.view.KeyEvent)` events to this function, views using ListPopupWindow can have it dismiss the popup when the back key is pressed.

| Parameters |
|---|---|
| `int keyCode` | keyCode param passed to the host view's onKeyPreIme |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event` | event param passed to the host view's onKeyPreIme |

| Returns |
|---|---|
| `boolean` | true if the event was handled, false if it was ignored. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setModal(boolean)` |   |

### onKeyUp

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

```
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event)
```

Filter key up events. By forwarding key up events to this function, views using non-modal ListPopupWindow can have it handle key selection of items.

| Parameters |
|---|---|
| `int keyCode` | keyCode param passed to the host view's onKeyUp |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event` | event param passed to the host view's onKeyUp |

| Returns |
|---|---|
| `boolean` | true if the event was handled, false if it was ignored. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setModal(boolean)` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#onKeyDown(int,android.view.KeyEvent)` |   |

### performItemClick

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

```
public boolean performItemClick(int position)
```

Perform an item click operation on the specified list adapter position.

| Parameters |
|---|---|
| `int position` | Adapter position for performing the click |

| Returns |
|---|---|
| `boolean` | true if the click action could be performed, false if not. (e.g. if the popup was not showing, this method would return false.) |

### postShow

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

```
public void postShow()
```

Post a `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#show()` call to the UI thread.

### setAdapter

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

```
public void setAdapter(@Nullable ListAdapter adapter)
```

Sets the adapter that provides the data and the views to represent the data in this popup window.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/ListAdapter.html adapter` | The adapter to use to create this window's content. |

### setAnchorView

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

```
public void setAnchorView(@Nullable View anchor)
```

Sets the popup's anchor view. This popup will always be positioned relative to the anchor view when shown.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html anchor` | The view to use as an anchor. |

### setAnimationStyle

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

```
public void setAnimationStyle(@StyleRes int animationStyle)
```

Set an animation style to use when the popup window is shown or dismissed.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/StyleRes int animationStyle` | Animation style to use. |

### setBackgroundDrawable

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

```
public void setBackgroundDrawable(@Nullable Drawable d)
```

Sets a drawable to be the background for the popup window.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html d` | A drawable to set as the background. |

### setContentWidth

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

```
public void setContentWidth(int width)
```

Sets the width of the popup window by the size of its content. The final width may be larger to accommodate styled window dressing.

| Parameters |
|---|---|
| `int width` | Desired width of content in pixels. |

### setDropDownGravity

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

```
public void setDropDownGravity(int gravity)
```

Set the gravity of the dropdown list. This is commonly used to set gravity to START or END for alignment with the anchor.

| Parameters |
|---|---|
| `int gravity` | Gravity value to use |

### setEpicenterBounds

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

```
public void setEpicenterBounds(@Nullable Rect bounds)
```

Specifies the custom anchor-relative bounds of the popup's transition epicenter.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Rect.html bounds` | anchor-relative bounds or `null` to use default epicenter |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getEpicenterBounds()` |   |

### setHeight

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

```
public void setHeight(int height)
```

Sets the height of the popup window in pixels. Can also be `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#MATCH_PARENT()`.

| Parameters |
|---|---|
| `int height` | Height of the popup window must be a positive value, `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#MATCH_PARENT()`, or `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#WRAP_CONTENT()`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if height is set to negative value |

### setHorizontalOffset

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

```
public void setHorizontalOffset(int offset)
```

Set the horizontal offset of this popup from its anchor view in pixels.

| Parameters |
|---|---|
| `int offset` | The horizontal offset of the popup from its anchor. |

### setInputMethodMode

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

```
public void setInputMethodMode(int mode)
```

Control how the popup operates with an input method: one of `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_FROM_FOCUSABLE()`, `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NEEDED()`, or `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#INPUT_METHOD_NOT_NEEDED()`.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to the `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#show()` method.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getInputMethodMode()` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#show()` |   |

### setListSelector

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

```
public void setListSelector(Drawable selector)
```

Sets a drawable to use as the list item selector.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html selector` | List selector drawable to use in the popup. |

### setModal

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

```
public void setModal(boolean modal)
```

Set whether this window should be modal when shown.

If a popup window is modal, it will receive all touch and key input. If the user touches outside the popup window's content area the popup window will be dismissed.

| Parameters |
|---|---|
| `boolean modal` | `true` if the popup window should be modal, `false` otherwise. |

### setOnDismissListener

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

```
public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener listener)
```

Set a listener to receive a callback when the popup is dismissed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/PopupWindow.OnDismissListener.html listener` | Listener that will be notified when the popup is dismissed. |

### setOnItemClickListener

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

```
public void setOnItemClickListener(
    @Nullable AdapterView.OnItemClickListener clickListener
)
```

Sets a listener to receive events when a list item is clicked.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html clickListener` | Listener to register |

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/AdapterView.html#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener)` |   |

### setOnItemSelectedListener

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

```
public void setOnItemSelectedListener(
    @Nullable AdapterView.OnItemSelectedListener selectedListener
)
```

Sets a listener to receive events when a list item is selected.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/widget/AdapterView.OnItemSelectedListener.html selectedListener` | Listener to register. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/AdapterView.html#setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener)` |   |

### setPromptPosition

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

```
public void setPromptPosition(int position)
```

Set where the optional prompt view should appear. The default is `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_ABOVE()`.

| Parameters |
|---|---|
| `int position` | A position constant declaring where the prompt should be displayed. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_ABOVE()` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#POSITION_PROMPT_BELOW()` |   |

### setPromptView

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

```
public void setPromptView(@Nullable View prompt)
```

Set a view to act as a user prompt for this popup window. Where the prompt view will appear is controlled by `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#setPromptPosition(int)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.html prompt` | View to use as an informational prompt. |

### setSelection

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

```
public void setSelection(int position)
```

Set the selected position of the list. Only valid when `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#isShowing()` == `true`.

| Parameters |
|---|---|
| `int position` | List position to set as selected. |

### setSoftInputMode

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

```
public void setSoftInputMode(int mode)
```

Sets the operating mode for the soft input area.

| Parameters |
|---|---|
| `int mode` | The desired mode, see `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#softInputMode` for the full list |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#softInputMode` |   |
| `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#getSoftInputMode()` |   |

### setVerticalOffset

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

```
public void setVerticalOffset(int offset)
```

Set the vertical offset of this popup from its anchor view in pixels.

| Parameters |
|---|---|
| `int offset` | The vertical offset of the popup from its anchor. |

### setWidth

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

```
public void setWidth(int width)
```

Sets the width of the popup window in pixels. Can also be `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#MATCH_PARENT()` or `https://developer.android.com/reference/androidx/appcompat/widget/ListPopupWindow#WRAP_CONTENT()`.

| Parameters |
|---|---|
| `int width` | Width of the popup window. |

### setWindowLayoutType

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

```
public void setWindowLayoutType(int layoutType)
```

Set the layout type for this popup window.

See `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#type` for possible values.

| Parameters |
|---|---|
| `int layoutType` | Layout type for this window. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#type` |   |

### show

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

```
public void show()
```

Show the popup list. If the list is already showing, this method will recalculate the popup's size and position.