Problem with LayoutInflater Android
So here is my code in View.
public class TheView extends View {
..
public boolean onKeyDown(int keyCode, KeyEvent event){
....
LayoutInflater inflater = this.game.getLayoutInflater();
inflater.inflate(R.layout.status, null);
....
}
}
And here is the xml file code which is named as "status.xml"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/app_name"/>
</menu>
"TheView" is called from another activity. And in the View i have drawn a canvas and have painted some graphics on top of it. I need to get a inflated menu on top of that. But when i try it with the given code it gives the following error
04-10 20:05:27.090: ERROR/AndroidRuntime(2208): FATAL EXCEPTION: main
04-10 20:05:27.090: ERROR/AndroidRuntime(2208): android.view.InflateException: Binary XML file line #2: Error inflating class men开发者_如何转开发u
04-10 20:05:27.090: ERROR/AndroidRuntime(2208): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
04-10 20:05:27.090: ERROR/AndroidRuntime(2208): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-10 20:05:27.090: ERROR/AndroidRuntime(2208): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
Any suggestions???
You have to use MenuInflater
to inflate a menu. And if you want to inflate a layout then do not use menu
tag.
精彩评论