سلام
اطلاعات کامل در مورد دیالوگ ها را میتوانید در این آدرس مطالعه کنید: http://developer.android.com/guide/t...i/dialogs.html
این هم یک مثال:
AlertDialogDemo Activity:
package m.p.s;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class AlertDialogDemo extends Activity {
Button btnGo;
EditText txtMsg;
String msg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
txtMsg = (EditText)findViewById(R.id.txtMsg);
btnGo = (Button) findViewById(R.id.btnGo);
btnGo.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
AlertDialog diaBox = makeAndShowDialogBox();
diaBox.show();
txtMsg.setText("I am here!");
}
});
}//onCreate
private AlertDialog makeAndShowDialogBox(){
AlertDialog myQuittingDialogBox =
new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle("Terminator")
.setMessage("Are you sure that you want to quit?")
.setIcon(R.drawable.ic_launcher)
//set three option buttons
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "YES" goes here
msg = "YES " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})//setPositiveButton
/* .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "Cancel " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})*/
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "NO " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})//setNegativeButton
.create();
return myQuittingDialogBox;
}
}//AndSelectionWidgets
dialog.xml Layout:
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<Button
android:text="GO"
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:hint="click the button"
android:id="@+id/txtMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
</LinearLayout>
منبع: http://www.java-samples.com/showtuto...utorialid=1513