public class ListPopupWindow
extends java.lang.Object
ListPopupWindow
Modifier and Type | Class and Description |
---|---|
static class |
ListPopupWindow.ForwardingListener
Abstract class that forwards touch events to a
ListPopupWindow . |
Modifier and Type | Field and Description |
---|---|
static int |
INPUT_METHOD_FROM_FOCUSABLE
Mode for
setInputMethodMode(int) : the requirements for the
input method should be based on the focusability of the popup. |
static int |
INPUT_METHOD_NEEDED
Mode for
setInputMethodMode(int) : this popup always needs to
work with an input method, regardless of whether it is focusable. |
static int |
INPUT_METHOD_NOT_NEEDED
Mode for
setInputMethodMode(int) : this popup never needs to
work with an input method, regardless of whether it is focusable. |
static int |
MATCH_PARENT
Alias for
ViewGroup.LayoutParams#MATCH_PARENT . |
static int |
POSITION_PROMPT_ABOVE
The provided prompt view should appear above list content.
|
static int |
POSITION_PROMPT_BELOW
The provided prompt view should appear below list content.
|
static int |
WRAP_CONTENT
Alias for
ViewGroup.LayoutParams#WRAP_CONTENT . |
Constructor and Description |
---|
ListPopupWindow(android.content.Context context)
Create a new, empty popup window capable of displaying items from a ListAdapter.
|
ListPopupWindow(android.content.Context context,
android.util.AttributeSet attrs)
Create a new, empty popup window capable of displaying items from a ListAdapter.
|
ListPopupWindow(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
Create a new, empty popup window capable of displaying items from a ListAdapter.
|
ListPopupWindow(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Create a new, empty popup window capable of displaying items from a ListAdapter.
|
Modifier and Type | Method and Description |
---|---|
void |
clearListSelection()
Clear any current list selection.
|
android.view.View.OnTouchListener |
createDragToOpenListener(android.view.View src)
Returns an
View.OnTouchListener that can be added to the source view
to implement drag-to-open behavior. |
void |
dismiss()
Dismiss the popup window.
|
android.view.View |
getAnchorView()
Returns the view that will be used to anchor this popup.
|
int |
getAnimationStyle()
Returns the animation style that will be used when the popup window is shown or dismissed.
|
android.graphics.drawable.Drawable |
getBackground() |
int |
getHeight() |
int |
getHorizontalOffset() |
int |
getInputMethodMode()
Return the current value in
setInputMethodMode(int) . |
ListView |
getListView() |
PopupWindow |
getPopup() |
int |
getPromptPosition() |
java.lang.Object |
getSelectedItem() |
long |
getSelectedItemId() |
int |
getSelectedItemPosition() |
android.view.View |
getSelectedView() |
int |
getSoftInputMode()
Returns the current value in
setSoftInputMode(int) . |
int |
getVerticalOffset() |
int |
getWidth() |
boolean |
isDropDownAlwaysVisible() |
boolean |
isInputMethodNotNeeded() |
boolean |
isModal()
Returns whether the popup window will be modal when shown.
|
boolean |
isShowing() |
boolean |
onKeyDown(int keyCode,
android.view.KeyEvent event)
Filter key down events.
|
boolean |
onKeyPreIme(int keyCode,
android.view.KeyEvent event)
Filter pre-IME key events.
|
boolean |
onKeyUp(int keyCode,
android.view.KeyEvent event)
Filter key down events.
|
boolean |
performItemClick(int position)
Perform an item click operation on the specified list adapter position.
|
void |
postShow()
Post a
show() call to the UI thread. |
void |
setAdapter(android.widget.ListAdapter adapter)
Sets the adapter that provides the data and the views to represent the data
in this popup window.
|
void |
setAnchorView(android.view.View anchor)
Sets the popup's anchor view.
|
void |
setAnimationStyle(int animationStyle)
Set an animation style to use when the popup window is shown or dismissed.
|
void |
setBackgroundDrawable(android.graphics.drawable.Drawable background) |
void |
setContentWidth(int width)
Sets the width of the popup window by the size of its content.
|
void |
setDropDownAlwaysVisible(boolean dropDownAlwaysVisible)
Sets whether the drop-down should remain visible under certain conditions.
|
void |
setDropDownGravity(int gravity)
Set the gravity of the dropdown list.
|
void |
setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch)
Forces outside touches to be ignored.
|
void |
setHeight(int height)
Sets the height of the popup window in pixels.
|
void |
setHorizontalOffset(int offset)
Set the horizontal offset of this popup from its anchor view in pixels.
|
void |
setInputMethodMode(int mode)
Control how the popup operates with an input method: one of
INPUT_METHOD_FROM_FOCUSABLE , INPUT_METHOD_NEEDED ,
or INPUT_METHOD_NOT_NEEDED . |
void |
setItemAnimation(int id) |
void |
setItemAnimationOffset(int offset) |
void |
setListSelector(android.graphics.drawable.Drawable selector)
Sets a drawable to use as the list item selector.
|
void |
setModal(boolean modal)
Set whether this window should be modal when shown.
|
void |
setOnDismissListener(android.widget.PopupWindow.OnDismissListener listener)
Set a listener to receive a callback when the popup is dismissed.
|
void |
setOnItemClickListener(android.widget.AdapterView.OnItemClickListener clickListener)
Sets a listener to receive events when a list item is clicked.
|
void |
setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener selectedListener)
Sets a listener to receive events when a list item is selected.
|
void |
setPromptPosition(int position)
Set where the optional prompt view should appear.
|
void |
setPromptView(android.view.View prompt)
Set a view to act as a user prompt for this popup window.
|
void |
setSelection(int position)
Set the selected position of the list.
|
void |
setSoftInputMode(int mode)
Sets the operating mode for the soft input area.
|
void |
setVerticalOffset(int offset)
Set the vertical offset of this popup from its anchor view in pixels.
|
void |
setWidth(int width)
Sets the width of the popup window in pixels.
|
void |
show()
Show the popup list.
|
public static final int POSITION_PROMPT_ABOVE
public static final int POSITION_PROMPT_BELOW
public static final int MATCH_PARENT
ViewGroup.LayoutParams#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.public static final int WRAP_CONTENT
ViewGroup.LayoutParams#WRAP_CONTENT
.
If used to specify a popup width, the popup will use the width of its content.public static final int INPUT_METHOD_FROM_FOCUSABLE
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.public static final int INPUT_METHOD_NEEDED
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.public static final int INPUT_METHOD_NOT_NEEDED
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.public ListPopupWindow(android.content.Context context)
setBackgroundDrawable(Drawable)
.context
- Context used for contained views.public ListPopupWindow(android.content.Context context, android.util.AttributeSet attrs)
setBackgroundDrawable(Drawable)
.context
- Context used for contained views.attrs
- Attributes from inflating parent views used to style the popup.public ListPopupWindow(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
setBackgroundDrawable(Drawable)
.context
- Context used for contained views.attrs
- Attributes from inflating parent views used to style the popup.defStyleAttr
- Default style attribute to use for popup content.public ListPopupWindow(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
setBackgroundDrawable(Drawable)
.context
- Context used for contained views.attrs
- Attributes from inflating parent views used to style the popup.defStyleAttr
- Default style attribute to use for popup content.defStyleRes
- Default style to use for popup content.public void setItemAnimation(int id)
public void setItemAnimationOffset(int offset)
public void setBackgroundDrawable(android.graphics.drawable.Drawable background)
public android.graphics.drawable.Drawable getBackground()
public void setAdapter(android.widget.ListAdapter adapter)
adapter
- The adapter to use to create this window's content.public void setPromptPosition(int position)
POSITION_PROMPT_ABOVE
.position
- A position constant declaring where the prompt should be displayed.POSITION_PROMPT_ABOVE
,
POSITION_PROMPT_BELOW
public int getPromptPosition()
POSITION_PROMPT_ABOVE
,
POSITION_PROMPT_BELOW
public void setModal(boolean modal)
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.
modal
- true
if the popup window should be modal, false
otherwise.public boolean isModal()
true
if the popup window will be modal, false
otherwise.public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch)
isDropDownAlwaysVisible()
is
false, we allow outside touch to dismiss the dropdown. If this is set to true, then we
ignore outside touch even when the drop down is not set to always visible.public void setDropDownAlwaysVisible(boolean dropDownAlwaysVisible)
getAnchorView()
regardless
of the size or content of the list. getBackground()
will fill any space
that is not used by the list.dropDownAlwaysVisible
- Whether to keep the drop-down visible.public boolean isDropDownAlwaysVisible()
public void setSoftInputMode(int mode)
mode
- The desired mode, see
WindowManager.LayoutParams.softInputMode
for the full listWindowManager.LayoutParams.softInputMode
,
getSoftInputMode()
public int getSoftInputMode()
setSoftInputMode(int)
.setSoftInputMode(int)
,
WindowManager.LayoutParams.softInputMode
public void setListSelector(android.graphics.drawable.Drawable selector)
selector
- List selector drawable to use in the popup.public void setAnimationStyle(int animationStyle)
animationStyle
- Animation style to use.public int getAnimationStyle()
public android.view.View getAnchorView()
public void setAnchorView(android.view.View anchor)
anchor
- The view to use as an anchor.public int getHorizontalOffset()
public void setHorizontalOffset(int offset)
offset
- The horizontal offset of the popup from its anchor.public int getVerticalOffset()
public void setVerticalOffset(int offset)
offset
- The vertical offset of the popup from its anchor.public void setDropDownGravity(int gravity)
gravity
- Gravity value to usepublic int getWidth()
public void setWidth(int width)
MATCH_PARENT
or WRAP_CONTENT
.width
- Width of the popup window.public void setContentWidth(int width)
width
- Desired width of content in pixels.public int getHeight()
public void setHeight(int height)
MATCH_PARENT
.height
- Height of the popup window.public void setOnItemClickListener(android.widget.AdapterView.OnItemClickListener clickListener)
clickListener
- Listener to registerAdapterView.setOnItemClickListener(AdapterView.OnItemClickListener)
public void setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener selectedListener)
selectedListener
- Listener to register.AdapterView.setOnItemSelectedListener(AdapterView.OnItemSelectedListener)
public void setPromptView(android.view.View prompt)
setPromptPosition(int)
.prompt
- View to use as an informational prompt.public void postShow()
show()
call to the UI thread.public void show()
public void dismiss()
public void setOnDismissListener(android.widget.PopupWindow.OnDismissListener listener)
listener
- Listener that will be notified when the popup is dismissed.public void setInputMethodMode(int mode)
INPUT_METHOD_FROM_FOCUSABLE
, INPUT_METHOD_NEEDED
,
or 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 show()
method.
getInputMethodMode()
,
show()
public int getInputMethodMode()
setInputMethodMode(int)
.setInputMethodMode(int)
public void setSelection(int position)
isShowing()
== true
.position
- List position to set as selected.public void clearListSelection()
isShowing()
== true
.public boolean isShowing()
true
if the popup is currently showing, false
otherwise.public boolean isInputMethodNotNeeded()
true
if this popup is configured to assume the user does not need
to interact with the IME while it is showing, false
otherwise.public boolean performItemClick(int position)
position
- Adapter position for performing the clickpublic java.lang.Object getSelectedItem()
public int getSelectedItemPosition()
ListViewCompat.INVALID_POSITION
if isShowing()
== false
.AdapterView.getSelectedItemPosition()
public long getSelectedItemId()
AdapterView.INVALID_ROW_ID
if isShowing()
== false
.AdapterView.getSelectedItemId()
public android.view.View getSelectedView()
isShowing()
== false
.AbsListView.getSelectedView()
public ListView getListView()
ListView
displayed within the popup window.
Only valid when isShowing()
== true
.public PopupWindow getPopup()
public boolean onKeyDown(int keyCode, android.view.KeyEvent event)
keyCode
- keyCode param passed to the host view's onKeyDownevent
- event param passed to the host view's onKeyDownsetModal(boolean)
public boolean onKeyUp(int keyCode, android.view.KeyEvent event)
keyCode
- keyCode param passed to the host view's onKeyUpevent
- event param passed to the host view's onKeyUpsetModal(boolean)
public boolean onKeyPreIme(int keyCode, android.view.KeyEvent event)
View.onKeyPreIme(int, KeyEvent)
events to this function, views using ListPopupWindow can have it dismiss the popup
when the back key is pressed.keyCode
- keyCode param passed to the host view's onKeyPreImeevent
- event param passed to the host view's onKeyPreImesetModal(boolean)
public android.view.View.OnTouchListener createDragToOpenListener(android.view.View src)
View.OnTouchListener
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 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);
src
- the view on which the resulting listener will be set