How to use AlertDialog.Builder in Android applications
Понедельник, Февраль 25th, 2008It’s a tiny example about an using of alert dialogs (viz, AlertDialog.Builder). If you want to supplement this sample by some material, write me please
package maximyudin.AlertDialogBuilderSample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class AlertDialogBuilderSample extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final Button btnQuit = (Button) findViewById(R.id.btnQuit);
btnQuit.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
new AlertDialog.Builder(AlertDialogBuilderSample.this)
.setTitle(“Question”)
.setMessage(“Are you sure that you want to quit?”)
.setIcon(R.drawable.question)
.setPositiveButton(“Yes”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
})
.setNegativeButton(“No”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}
});












