我希望在另一个片段的位置文本中获取项目
public boolean onContextItemSelected(MenuItem item) {
// Get extra info about list item that was long-pressed
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
// Perform action according to selected item from context menu
switch (item.getItemId()) {
case CONTEXTMENU_OPTION1:
// Show message
Fragment fragment = new detail();
Bundle args = new Bundle();
args.putString("Menuu",getActivity().getApplicationContext().toString());
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container,fragment).addToBackStack("mm").commit();
Toast.makeText(getActivity().getApplicationContext(), "View", Toast.LENGTH_SHORT).show();
break;
答案 0 :(得分:0)
getItemId()
为您提供一个整数(菜单中项目的位置......首先为0,等等。)。
我不明白您的问题,但如果您尝试打开另一个片段,请点击菜单中的某个项目。然后您的开关应如下所示:
switch(item.getItemId()){
//This will be initialized if the user selects first item in Men
case 0:
/** replace your fragment uppon clicking the first item in menu*/
break;
等
如果这不是您所寻求的,那么我不明白您的问题。我们也不知道CONTEXTMENU_OPTION1
是什么
在你的情况下。