【发布时间】:2011-03-22 12:38:37
【问题描述】:
我想显示膨胀视图的上下文菜单。这是代码示例:
对于grid_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:antialias="true" />
现在我在我的活动课程中使用它:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Select action");
menu.add(0, 1, 0, "Action1");
menu.add(0, 2, 0, "Action2");
super.onCreateContextMenu(menu, v, menuInfo);
}
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView imageView = (ImageView) inflater.inflate(R.layout.grid_layout, null);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerForContextMenu(v);
openContextMenu(v);
}
});
此代码运行没有任何错误,但是当我单击 imageView 时上下文菜单不显示。这段代码有什么问题吗?
【问题讨论】:
-
我在这里做类似的事情!!!stackoverflow.com/questions/16621070/…
标签: android view contextmenu