Dec 2, 2010

AlertDialog.Builder - a simple way to create AlertDialog


eg.

package com.android.coding.HelloWorld;

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 HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AlertDialog.Builder(HelloWorld.this)
.setTitle("AlertDialog").setMessage("Hello!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}});
}
}

No comments:

Post a Comment

Infolinks In Text Ads