Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.34 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android Checkbox asking confirmation twice when unchecking
  2. mEventAttendingCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {      
  3.         @Override
  4.         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  5.             if(isChecked){
  6.                 //do nothing
  7.             } else {
  8.                 Context mContext = EventSingleViewActivity.this;
  9.                 final Dialog dialog = new Dialog(mContext);
  10.  
  11.                 dialog.setCancelable(true);
  12.  
  13.                 Button confirmButton = (Button) dialog.findViewById(R.id.confirmButton);    
  14.                 confirmButton.setOnClickListener(new View.OnClickListener() {
  15.                     @Override
  16.                     public void onClick(View v){
  17.                         //do something
  18.                     }
  19.                 });
  20.  
  21.  
  22.                 Button cancelButton = (Button) dialog.findViewById(R.id.cancelButton);  
  23.                 cancelButton.setOnClickListener(new View.OnClickListener() {
  24.                     @Override
  25.                     public void onClick(View v) {
  26.                         dialog.dismiss();
  27.                         mEventAttendingCheckBox.setChecked(true);
  28.                     }
  29.                 });
  30.  
  31.  
  32.                 dialog.show();
  33.  
  34.             }
  35.         }
  36.     });
  37.        
  38. if(flag == false)
  39.  // open dialog
  40. else
  41.  // just uncheck button