申请文本菜单自定义标题 [英] Applying a custom header for ContextMenu
问题描述
我想自定义标题适用于文本菜单
A 的ListView
的。这里的code。
I'm trying to apply a custom header to the ContextMenu
of a ListView
. Here's the code.
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
View header = View.inflate(getSherlockActivity(),
R.id.context_menu_header, (ViewGroup) v);
TextView title = (TextView) header
.findViewById(R.id.context_menu_title);
title.setText(cursor.getString(1));
menu.setHeaderView(header);
android.view.MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
这code不能与资源$ NotFoundException:资源ID#0x7f050038键入#12H处无效
。在行查看标题= View.inflate(getSherlockActivity(),R.id.context_menu_header,(一个ViewGroup)V);
。我猜可能是因为参数(ViewGroup中)V
的。我怎样才能解决这个错误得到什么?
This code fails with a Resources$NotFoundException: Resource ID #0x7f050038 type #0x12 is not valid
. In the line View header = View.inflate(getSherlockActivity(), R.id.context_menu_header, (ViewGroup) v);
. I'm guessing probably because of param (ViewGroup) v
. How can I get around this error?
推荐答案
我用 R.id.context_menu_header
,而不是 R.layout .layout_file
,我不得不传递null为View.inflate方法的最后一个参数。
I was using R.id.context_menu_header
instead of a R.layout.layout_file
and I had to pass null for the last parameter of the View.inflate method.
这篇关于申请文本菜单自定义标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!