Android中未生成菜单

时间:2011-03-01 06:04:13

标签: android menuitem

这是我的代码我试图在onClick上实现一个简单的菜单。菜单按钮没有响应。你能帮我解决一下错误吗?

package com.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class menuitem extends Activity {
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menuitem, menu);
        return true;

    }       

        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle item selection
            switch (item.getItemId()) {
            case R.id.About:
                About();
                return true;
            case R.id.Exit:
                Exit();
                return true;
            default:
                return super.onOptionsItemSelected(item);
            }
        }    




    private void Exit() {
        // TODO Auto-generated method stub
        finish();
    }

    private void About() {
        // TODO Auto-generated method stub
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("APPLICATION VERSION-- 1.6")
               .setCancelable(false)
               .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       dialog.cancel();
                   }
               });

        AlertDialog alert = builder.create();
    }
}

1 个答案:

答案 0 :(得分:1)

您只是创建对话框....您需要调用show()才能显示它..