在代码执行到某一处会弹出一个NumberPicker,我希望在NumberPick选中值后再继续执行下面的代码,请问该怎么做呢,印象里有什么锁来着,行不行呢,下面是代码,麻烦大家帮忙看看,谢谢
autoClean.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
alert.setTitle("选择清理间隔(时)");
alert.show(); //这里弹出了对话框,我希望后面的代码在对话框点击了下面的确定按钮后执行,并且下面的代码不要写到确定按钮的监听器下
Log.d("TAG","fuck");
Intent intent = new Intent(ProccessesActivity.this,AutoCleanService.class);
getApplicationContext().startService(intent);
}else {
}
}
});
confirmTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor sharedPreferences=getSharedPreferences("data",MODE_PRIVATE).edit();
sharedPreferences.putInt("autoCleanTime",numberPicker.getValue());
sharedPreferences.commit();
Log.d("TAG","changed");
alert.dismiss();
}
});
Alert monitoring is definitely required. Either it is a callback when the button above the alert is clicked, or it is a callback to monitor the closing of the alert, which is determined according to the business.
As for the following code, you can place it elsewhere and make two callbacks. That’s it, just like: