0

これが私の AndroidMenuActivity.java ファイルです。

package com.example.caliexpeditionapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;

public class AndroidMenuActivity extends Activity {
    private WebView browser;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

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

    public boolean onContextItemSelected(MenuItem item)
    {
        onOptionsItemSelected(item);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch(item.getItemId())
        {
            case R.id.menu_refresh:
                browser = (WebView) findViewById(R.id.webkit);
                browser.reload();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

そして私のoption.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@+id/menu_refresh"
          android:icon="@drawable/ic_menu_refresh"
          android:title="@string/refresh" />

</menu>

そして最後に私のmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.caliexpeditionapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity android:name="com.example.caliexpeditionapp.MainActivity"
                  android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.caliexpeditionapp.AndroidMenuActivity">
        </activity>
    </application>

</manifest>

ロードは問題ありません。メニューボタンを押しても... 何もありません。エラーはありません。何もありません。

これは重複した質問である可能性が高いことはわかっていますが、他に何を検索すればよいかわかりませんでした。

4

2 に答える 2

1

あなたのXMLメニューファイルはoptions.xml- だからあなたはに変更する必要があるinflater.inflate(R.menu.option, menu);と言ったbinflater.inflate(R.menu.options, menu);

于 2013-03-26T01:55:18.640 に答える
0

を追加しonMenuItemSelected()ます。

/**
 * Hook called whenever an item in the options menu is selected.
 * @param item The menu item that was selected.
 * @return false to allow normal menu processing to proceed, true to consume it here.
 */
@Override
public boolean onMenuItemSelected (int featureId, MenuItem item) {
    final int itemId = item.getItemId();
    Toast.makeText(this, "Menu item clicked, index: " + itemId, Toast.LENGTH_SHORT).show();
    return super.onMenuItemSelected(featureId, item);
}
于 2013-03-26T05:47:04.480 に答える