我正在尝试将自定义标头应用于ContextMenu
. ListView
这是代码。
@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);
}
此代码失败并带有Resources$NotFoundException: Resource ID #0x7f050038 type #0x12 is not valid
. 在行View header = View.inflate(getSherlockActivity(), R.id.context_menu_header, (ViewGroup) v);
。我猜可能是因为 param (ViewGroup) v
。我怎样才能绕过这个错误?