Reputation: 17119
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?
Upvotes: 0
Views: 1752
Reputation: 17119
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.
Upvotes: 1
Reputation: 7892
My first though is an error in one of your XML-files. Some ID that is not defined correctly or something. It would be helpful if you would post some more code including the XML-file :)
Upvotes: 0