ホームに戻る
 メニュー

package org.example.helloworld;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class HelloWorld extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);

      LinearLayout ll = new LinearLayout(this);
      ll.setOrientation(LinearLayout.VERTICAL);
      setContentView(ll);

      TextView tv = new TextView(this);
      tv.setText("push menu");

      ll.addView(tv);
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
      menu.add(Menu.NONE, 0, 0, "A");
      menu.add(Menu.NONE, 1, 1, "B");
      return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem mi)
    {
      String str = null;

      if(mi.getItemId() == 0){
        str = "A";
      }
      else{
        str = "B";
      }

      AlertDialog.Builder adlg;
      adlg = new AlertDialog.Builder(HelloWorld.this);
      adlg.setTitle("Test");
      adlg.setMessage("Selected " + str);
      adlg.setPositiveButton("YES", null);
      adlg.show();

      return true;
    }
}

inserted by FC2 system