0

我正在将活动组用于选项卡组。

选项卡组 Activity 中的一个子 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);
}

下面给出了我在 child Achtivity 中编写的代码

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

请帮助我

4

1 回答 1

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

它对我有用

于 2012-12-28T10:07:25.330 回答