`

Android : CheckBox的listener, 弹出对话框

 
阅读更多

public class Play2Activity extends Activity {
	/** Called when the activity is first created. */
	private TextView result;
	private Button insert;
	private Button show;
	private Helper db;

	private EditText et_title;

	// private EditText et_show;

 //android API8

 

 

 

 

checkBox= (CheckBox) this.findViewById(R.id.checkBox);

//选中或非选中checkBox时的动作

checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

  if(checkBox.isChecked()){ //勾上这个checkBox 对应的动作
     openOptionsDialog();

    }else{
    ////

    }
   
   }

  });

 

//打开提示框

 private void openOptionsDialog() {
  String title = " a title";
  String msg = "this is a message";
  new AlertDialog.Builder(this).setTitle(title).setMessage(msg)
    .setPositiveButton("确认", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).show();

 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics