我在线性布局中制作了6个视图。我将在这里只发布一个和XML代码:
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="50dp"
android:minHeight="50dp" >
<View
android:id="@+id/viewMeni"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/meni"
android:clickable="true"
android:onClick="meniClick"
android:layout_margin="5dp" />
</LinearLayout>
单击viewMeni时如何显示定义的菜单?
答案 0 :(得分:0)
first find that view in your activity ... and then used registerforcontextmenu(yourname);
then
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.favourite, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int position = info.position;
switch (item.getItemId()) {
case R.id.connect:
return true;
case R.id.mark:
return true;
case R.id.delete:
return true;
default:
return super.onContextItemSelected(item);
}
}