活动组中的上下文菜单



我正在使用一个标签组活动组。

选项卡组Activity中的子Activity包含一个上下文菜单。但是当我点击菜单项时,在选中的上下文菜单项下编写的代码没有运行。

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);
}

在child activity中编写的代码如下

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;}

请帮帮我

Call

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);
}

它适合我

相关内容

  • 没有找到相关文章

最新更新