Dialog view use to show
inform text or get accept from user.
AlertDialog.Builder dialog=new
AlertDialog.Builder(second.this);
dialog.setIcon(R.drawable.image);
dialog.setTitle("Hello
world!");
dialog.setMessage("Hi,"+"\n"+"This is
Dialog view."+"\n"+"It float above another screen."); dialog.setNegativeButton("Cancel", new
OnClickListener(){
@Override
public void
onClick(DialogInterface arg0, int arg1) {
}
});
dialog.setPositiveButton("OK",new
OnClickListener() {
@Override
public void onClick(DialogInterface
arg0, int arg1) {
// TODO
Auto-generated method stub
}
});
dialog.show();
If we want to ask user
delete data or not, it simple to use Dialog.
Comment to setMessage, change setTitle to dialog.setTitle("Delete ?");
In button OK, add code to
delete.
If in file AndroidManifest, your
class declare set full screen.
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Even when you set background
white for Layout, dialog still look black.
Im
In this case, to make Dialog
white and remove icon on top screen, copy this line in to above setContentView.
requestWindowFeature(Window.FEATURE_NO_TITLE);
If you want more button, add
some lines.
dialog.setNeutralButton("Button
3", new OnClickListener() {
@Override
public void onClick(DialogInterface
arg0, int arg1) {
// TODO
Auto-generated method stub
//Do something
}
});
No comments:
Post a Comment