package ui.AlertRadioButtonSample; /* * アラートダイアログ上にラジオボタンと閉じるボタンが表示 */ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.widget.Toast; public class AlertRadioButtonSample extends Activity { AlertDialog alert; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Pick a color"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(AlertRadioButtonSample.this, items[item], Toast.LENGTH_SHORT).show(); } }); // Negativeボタン、リスナを設定 builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { alert.cancel(); } }); alert = builder.create(); alert.show(); } }