本文整理汇总了Java中android.view.MenuItem.OnMenuItemClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.OnMenuItemClickListener方法的具体用法?Java MenuItem.OnMenuItemClickListener怎么用?Java MenuItem.OnMenuItemClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.OnMenuItemClickListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateContextMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
String name = item.getTitle().toString();
mEtLocation.setText(name);
return true;
}
};
//clear menu
if (menu.size() != 0) {
menu.clear();
}
int id_view = v.getId();
switch (id_view) {
case R.id.arrow:
try {
mLocationList = mDbHelper.getLocationList();
} catch (NullObjectException e) {
Log.d(TAG, e.toString());
}
if (mLocationList == null || mLocationList.size() == 0) {
FunctionHelper.makeSToast(mActivity, mResources.getString(R.string.no_data_available));
} else {
int i = 0;
for (Location l : mLocationList) {
//Add menu item with groupId
menu.add(ID_GROUP_LOCATION, l.getLocation_id(), l.getLocation_id(), l.getLocation_name());
menu.getItem(i).setOnMenuItemClickListener(listener);
i++;
}
menu.setHeaderTitle(R.string.choose_a_location);
}
break;
}
}
示例2: setOnItemSelectedListener
import android.view.MenuItem; //导入方法依赖的package包/类
public void setOnItemSelectedListener(
MenuItem.OnMenuItemClickListener listener) {
itemSelectedListener = listener;
}