Skip to content

Instantly share code, notes, and snippets.

@nommy
Created November 15, 2011 04:22
Show Gist options
  • Save nommy/1366128 to your computer and use it in GitHub Desktop.
Save nommy/1366128 to your computer and use it in GitHub Desktop.
android,UI,AlertDialog(3buttons)
package com.alertdialog;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class AlertDialogTestActivity extends Activity {
/** Called when the activity is first created. */
private final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//DialogBuilder
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("タイトル");
builder.setMessage("メッセージ");
//Dialog Buttonの記述
builder.setPositiveButton("肯定",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
// TODO 自動生成されたメソッド・スタブ
}
});
builder.setNeutralButton("中立",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO 自動生成されたメソッド・スタブ
}
});
builder.setNegativeButton("否定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO 自動生成されたメソッド・スタブ
}
});
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);
final Button button = new Button(this);
button.setText("Open Dialog");
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Dialog
AlertDialog dialog = builder.create();
dialog.show();
}
});
linearLayout.addView(button,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment