本文整理汇总了Java中android.widget.PopupMenu.setOnDismissListener方法的典型用法代码示例。如果您正苦于以下问题:Java PopupMenu.setOnDismissListener方法的具体用法?Java PopupMenu.setOnDismissListener怎么用?Java PopupMenu.setOnDismissListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.PopupMenu
的用法示例。
在下文中一共展示了PopupMenu.setOnDismissListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showPopupMenu
import android.widget.PopupMenu; //导入方法依赖的package包/类
/**
* Show a {@link PopupMenu}.
*
* @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
* needs to be the tag of a native view (shadow views can not be anchors)
* @param items the menu items as an array of strings
* @param success will be called with the position of the selected item as the first argument, or
* no arguments if the menu is dismissed
*/
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
UiThreadUtil.assertOnUiThread();
View anchor = mTagsToViews.get(reactTag);
if (anchor == null) {
throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
}
PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);
Menu menu = popupMenu.getMenu();
for (int i = 0; i < items.size(); i++) {
menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
}
PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
popupMenu.setOnMenuItemClickListener(handler);
popupMenu.setOnDismissListener(handler);
popupMenu.show();
}
示例2: onOptionsItemSelected
import android.widget.PopupMenu; //导入方法依赖的package包/类
/**
* Handle event when option item selected
*
* @param item The clicked item
*
* @return true or false indicate need to handle other menu item or not
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, "start FmRadioActivity.onOptionsItemSelected");
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
case R.id.fm_channel_list:
refreshImageButton(false);
refreshActionMenuItem(false);
refreshPopupMenuItem(false);
refreshActionMenuPower(false);
// Show favorite activity.
enterChannelList();
break;
case R.id.fm_power:
Log.d(TAG, "click fm_power menu");
if (mIsPlaying) {
refreshImageButton(false);
refreshActionMenuItem(false);
refreshPopupMenuItem(false);
refreshActionMenuPower(false);
exitService();
break;
}
powerUpFm();
break;
case R.id.fm_menu:
item.setEnabled(false);
mPopupMenu = new PopupMenu(mContext, findViewById(R.id.fm_menu));
Menu menu = mPopupMenu.getMenu();
mPopupMenu.getMenuInflater().inflate(R.menu.fm_menu, menu);
mPopupMenu.setOnMenuItemClickListener(this);
mPopupMenu.setOnDismissListener(this);
boolean isPlaying = mService.isPowerUp();
if (isPlaying) {
menu.findItem(R.id.fm_record).setEnabled(true);
menu.findItem(R.id.fm_sound_mode).setEnabled(!mService.isBtConnected());
menu.findItem(R.id.fm_sound_mode).setTitle(
mService.isSpeakerUsed() ? R.string.optmenu_earphone
: R.string.optmenu_speaker);
menu.findItem(R.id.fm_search).setEnabled(true);
}
refreshSoundModeVisiable();
mPopupMenu.show();
break;
default:
Log.e(TAG, "Error: Invalid options menu item.");
break;
}
Log.d(TAG, "end FmRadioActivity.onOptionsItemSelected");
return super.onOptionsItemSelected(item);
}