自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。

2012年4月7日土曜日

Android AlertDialog

AlertDialogでコンテキストメニューを表示する

Activity
package com.sqlendia.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Android2_21Activity extends Activity
{
    AlertDialog actions;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setTitle("アラーとダイヤログ");

        Button button = new Button(this);
        button.setText("選んでくださし");
        button.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                actions.show();
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("オプション");
        String[] optoins =
        { "オプション1", "オプション2", "オプション3" };

        builder.setItems(optoins, new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                switch (which)
                {
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                    break;
                default:
                    break;
                }
            }
        });

        builder.setNegativeButton("Cancel", null);
        actions = builder.create();

        setContentView(button);
    }
}



0 件のコメント:

コメントを投稿

ホームページ