java - menuitem.getmenuinfo() returns null for dynamically created views -
i have scrollview
embedded relativelayout
embedded linearlayout
.
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:paddingleft="16dp" android:paddingright="16dp" android:id="@+id/relativelayout"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/today" android:layout_alignparentleft="true" android:id="@+id/linearlayouttoday" android:animatelayoutchanges="true"> </linearlayout> </relativelayout> </scrollview>
i want add context menu checkbox
objects, added dynamically shown below.
private void additem() { checkbox ch = new checkbox(this); ch.settext("test"); registerforcontextmenu(ch); linearlayouttoday.addview(ch); }
the issue occurs in oncontextitemselected
method, value returned item.getmenuinfo()
null.
@override public boolean oncontextitemselected(menuitem item) { adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo(); system.out.println(info.targetview); return true; }
does know how resolve issue?
this problem caused because add context menu children, add context menu parent. however, supported other views (e.g. listview), not layouts.
Comments
Post a Comment