我在尝试ContextMenu使用该ActionBarSherlock库时遇到类型问题,正如您所知,它最终模仿/实现了 Android 支持库。
有一个SherlockFragmentActivity设置布局内容,并且在该内容中存在两个片段。其中一个片段是SherlockListFragment. 我打电话注册onCreate。SherlockListFragmentContextMenu
registerForContextMenu(getListView());
问题出在尝试膨胀菜单时。
listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
MenuInflater inflater = getSherlockActivity().getSupportMenuInflater();
inflater.inflate(R.menu.lot_menu, contextMenu);
}
});
由于方法参数中指定的类型,我无法调用inflate,但它期望com.actionbarsherlock.view.Menu传入的类型是android.view.ContextMenu.
我似乎遗漏了一些东西,因为Menu在操作栏中膨胀 a 是微不足道的,但是在ContextMenu使用支持框架时似乎会造成问题。
我如何适当注册以根据需要使用支持框架并随后膨胀ContextMenu?