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);
}
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?
I was using
R.id.context_menu_headerinstead of aR.layout.layout_fileand I had to pass null for the last parameter of the View.inflate method.