Development of the dialog Andrews

package com.lidaochen.test001;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.SystemClock;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    // click of a button pops up a dialog ordinary 
    public  void click1 (View v)
    {
        // configured by the builder Builder
         // The following parameters are used which are generally dialog context the this 
        AlertDialog.Builder Builder = new new AlertDialog.Builder ( the this );
        builder.setTitle("提示");
        builder.setMessage ( "I am your father never get!" );
         // set the cancel button 
        builder.setNegativeButton ( "Cancel", new new DialogInterface.OnClickListener () {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.e ( "Dialog", "cancel button is clicked" );
            }
        });
        // Set OK 
        builder.setPositiveButton ( "OK", new new DialogInterface.OnClickListener () {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.e ( "Dialog", "click the OK button!" );
            }
        });
        // and Toast must be the same as the last show out 
        builder.show ();
    }
    // click the radio button pops up a dialog 
    public  void click2 (View v)
    {
        // configured by the builder Builder
         // The following parameters are used which are generally dialog context the this 
        AlertDialog.Builder Builder = new new AlertDialog.Builder ( the this );
        builder.setTitle ( "Please select your favorite course" );
         Final String items [] = { "Android", "ios", "C", "C ++", "the Java", "Python", "C #" };
         // -1 for no item is selected 
        builder.setSingleChoiceItems (items, -1, new new DialogInterface.OnClickListener () {
            @Override
            public  void the onClick (DialogInterface Dialog, int Which) {
                 // the selected entry is taken out 
                String = Item items [Which];
                Toast.makeText(getApplicationContext(), item, Toast.LENGTH_SHORT).show();
                // close the dialog box 
                dialog.dismiss ();
            }
        });
        // and Toast must be the same as the last show out 
        builder.show ();
    }
    // click of a button pops up a multi-selection dialog 
    public  void CLICK3 (View v)
    {
        // configured by the builder Builder
         // The following parameters are used which are generally dialog context the this 
        AlertDialog.Builder Builder = new new AlertDialog.Builder ( the this );
        builder.setTitle ( "Please select your favorite fruit to eat" );
         Final String items [] = { "apple", "banana", "pear", "melon", "Watermelon," "lychee", "mango" } ;
         Final  Boolean [] = {checkItems to true , to false , to false , to false , to false , to false , to true };
        builder.setMultiChoiceItems(items, checkItems, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                Log.e("dialog", items[which]);
            }
        });
        // Set OK 
        builder.setPositiveButton ( "OK", new new DialogInterface.OnClickListener () {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                SB the StringBuffer = new new the StringBuffer ();
                 // data taken out of the selected entry 
                for ( int I = 0; I <checkItems.length; I ++ )
                {
                    // determine what the selected 
                    IF (checkItems [i])
                    {
                        String fruit = items[i];
                        sb.append(fruit + " ");
                    }
                }
                Toast.makeText(getApplicationContext(), sb.toString(), Toast.LENGTH_SHORT).show();
                // close the dialog box 
                dialog.dismiss ();
            }
        });
        // and Toast must be the same as the last show out 
        builder.show ();
    }
    // click of a button pops up a multi-selection dialog 
    public  void click4 (View v)
    {
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setTitle ( "death-defying being loaded ING" );
         // set about the progress bar style 
        dialog.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL);
         // and Toast must be the same as the last show out 
        dialog.show ();
         // create a child thread 
        new new the thread ()
        {
            public void run()
            {
                // set the maximum progress bar 
                dialog.setMax (100 );
                 // Set the current schedule 
                for ( int I = 0; I <100; I ++ )
                {
                    dialog.setProgress(i);
                    SystemClock.sleep(100);
                }
            };
        }.start();
    }
}

 

Guess you like

Origin www.cnblogs.com/duxie/p/11031013.html