我正在为选项卡组使用活动组。
选项卡组中的一个子Activity包含一个Contextmenu。但是当我点击菜单项时,在所选上下文菜单项下写的代码没有运行。
the code which i was written in tabgroup Activity is given below
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return getLocalActivityManager().getCurrentActivity().onContextItemSelected(item);
}
我在儿童活动中写的代码如下:
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
if(v.getId()==R.id.appointment_listview1)
{
AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo)menuInfo;
appointmnt_row item = (appointmnt_row)appListView.getItemAtPosition(info.position);
menu.setHeaderTitle(dateString);
menu.add(0, item.getId(), 0, "Delete");
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Delete")
{Log.e("delete",""+item1.getId());
} return true;}
请帮帮我
答案 0 :(得分:0)
致电
View view = getLocalActivityManager().startActivity("YourActivity", new
Intent(this,YourActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
ListView list = (ListView) view.findViewById(android.R.id.list); // find your view,for example list.
list.setOnCreateContextMenuListener(this);
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
Log.v(null, "ITEM CREATED");
menu.add(Menu.NONE, 0, Menu.NONE, "1 item");
getLocalActivityManager().getCurrentActivity().onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
Log.v(null, "ITEM SELECTED");
return getLocalActivityManager().getCurrentActivity().onContextItemSelected(item);
}
它适用于我