Created
November 15, 2011 04:22
-
-
Save nommy/1366128 to your computer and use it in GitHub Desktop.
android,UI,AlertDialog(3buttons)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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