gpt4 book ai didi

选项菜单上的android开发

转载 作者:行者123 更新时间:2023-11-29 00:42:26 27 4
gpt4 key购买 nike

我是使用 PhoneGap 进行 Android 开发的新手,我尝试通过来自 http://developer.android.com/guide/topics/ui/menus.html 的教程构建一个选项菜单, 但它总是给出如下错误消息:

[2011-12-20 16:45:28 - HelloPhoneGap] W/ResourceType(23444): Bad XML block: header size >84 or total size 0 is larger than data size 0 [2011-12-20 16:45:28 - HelloPhoneGap] C:..\workspace\HelloPhoneGap\res\menu\menu.xml:3: >error: Error: No resource found that matches the given name (at 'title' with value >'@string/new_game'). [2011-12-20 16:45:28 - HelloPhoneGap] C:..\workspace\HelloPhoneGap\res\menu\menu.xml:5: >error: Error: No resource found that matches the given name (at 'title' with value >'@string/help').

控制台代码如下:

package com.phonegap.helloworld;

import android.os.Bundle;
import com.phonegap.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/jqm/index.htm");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_MENU) {
return false;
}else{
return super.onKeyDown(keyCode, event);
}

}

}

菜单.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:title="@string/new_game" />
<item android:id="@+id/help"
android:title="@string/help" />
</menu>

有没有人告诉我错误的原因?

非常感谢!


在 string.xml 中定义字符串后,错误消失了,但我遇到了如下新错误

KeyEvent cannot be resolved to a type   App.java    /HelloPhoneGap/src/com/phonegap/helloworld  line 39 Java Problem
KeyEvent cannot be resolved to a variable App.java /HelloPhoneGap/src/com/phonegap/helloworld line 40 Java Problem
Menu cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 17 Java Problem
MenuInflater cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 18 Java Problem
MenuItem cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 24 Java Problem

最佳答案

你必须定义字符串 new_game 的值如下

<resources>
<string name="new_game">Your String</string>
<string name="help">Your String</string>
</resources>

引用this

您可以创建值 xml 文件 - 如果您使用的是 eclipse,则右键单击该项目并选择其他,然后选择 android xml 文件,然后给定窗口选择资源类型作为值,

关于选项菜单上的android开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8573124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com