本文整理匯總了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;
}