Saturday, July 25, 2015

android: Create a Dialog with positive and negative button

public void dialog() {
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                     //Do your own work 
                   // turn3GOn();  break;            
               case DialogInterface.BUTTON_NEGATIVE:
                    //Do your own work 
// close();  
           }
        }
    };  
   AlertDialog.Builder builder = new AlertDialog.Builder(this); 
   LinearLayout linearLayout = new LinearLayout(this);   
   linearLayout.setOrientation(LinearLayout.VERTICAL); 
   TextView textViewDialog = new TextView(this);   
   textViewDialog.setText("Notice!");   
   textViewDialog.setGravity(Gravity.CENTER); 
  //textViewDialog.setCompoundDrawablesWithIntrinsicBounds(R.drawable.evhome, 0, 0, 0);  
  textViewDialog.setCompoundDrawablePadding(20);  
  textViewDialog.setTextColor(Color.parseColor("#FFFFFF")); 
  textViewDialog.setPadding(20, 10, 10, 10);   
  textViewDialog.setBackgroundColor(Color.parseColor("#33B5E5"));  
  textViewDialog.setTextSize(22);   
  TextView textViewDialog2 = new TextView(this); 
  textViewDialog2.setTypeface(Typeface.SERIF);  
  textViewDialog2.setText("Please Turn On Your Data Connection ");  
  textViewDialog2.setTextColor(Color.parseColor("#000000"));  
  textViewDialog2.setPadding(20, 20, 20, 20);  
  textViewDialog2.setBackgroundColor(Color.parseColor("#F5F5F5")); 
  textViewDialog2.setTextSize(15);  
  linearLayout.addView(textViewDialog);  
  linearLayout.addView(textViewDialog2);  
  builder.setView(linearLayout);  
  builder.setPositiveButton(Html.fromHtml("<b>" + "Ok" + "<b>"), dialogClickListener);  
  bui lder.setNegativeButton(Html.fromHtml("<b>" + "Cancel" + "<b>"), dialogClickListener);    bui lder.show();}

No comments:

Post a Comment