Android Dialog Box Example

Android Dialog Box Example - Hello friends U-See, In the article you read in this time with the title Android Dialog Box Example, We have prepared this article well for you to read and take the information in it. Hopefully the contents of the post Artikel Android, Which we write you can understand. Okay, happy reading.

Title: Android Dialog Box Example
link : Android Dialog Box Example

Read also


Android Dialog Box Example

Android Dialog Box Example...
Open xml file and below code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="24dp"
        android:layout_marginTop="17dp"
        android:text="CLOSE"
        android:onClick="close" />
</RelativeLayout>


Now open java file and paste below code

package selecom.alert;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.app.AlertDialog.Builder;
importandroid.app.Dialog;
importandroid.content.DialogInterface;
importandroid.view.View;
importandroid.widget.Toast;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
    }
    public void close(View v)
    {
      onCreateDialog(10);
    }

protected Dialog onCreateDialog(int id)
{
      switch(id)
      {
      case 10:
            Builder builder=newAlertDialog.Builder(this);
            builder.setMessage("Activity will close!!!");
            builder.setTitle("Warning...");
            builder.setIcon(R.drawable.warning_image);
//button 
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                 
                  @Override
                  public voidonClick(DialogInterface dialog, int which)
                  {
                        Toast.makeText(getApplicationContext(), "Nothing happened", Toast.LENGTH_LONG).show();
                       
                  }
            });
//button
      builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
                 
                  @Override
                  public voidonClick(DialogInterface dialog, int which)
                  {
                        finish();
                       
                  }
            });
//button
      builder.setNeutralButton("Thinking", newDialogInterface.OnClickListener() {
           
            @Override
            public voidonClick(DialogInterface dialog, int which)
            {
                  Toast.makeText(getApplicationContext(), "i have to think", Toast.LENGTH_LONG).show();
                 
            }
      });
           
      AlertDialog dialog=builder.create();
      dialog.show();
           
      }
      return super.onCreateDialog(id);
     
}
  
} 

We can use maximum three buttons in dialog box by default and builder is used to create dialog box. Sequence of the buttons to appear on box: positive, neutral than negative.


That's Android Dialog Box Example

That's an article Android Dialog Box Example This time, hopefully can benefit for you all. Well, see you in other article postings.

You are now reading the article Android Dialog Box Example With link address https://u-see1.blogspot.com/2017/06/android-dialog-box-example.html

Postingan terkait:

Belum ada tanggapan untuk "Android Dialog Box Example"

Post a Comment