Problem adding check box to dialog box
Hi I’ve been having some difficulty adding a checkbox to a dialog window. The dialog contains instructions and I don’t want it to show every time. I want it to stop showing when the user checks the checkbox and clicks ok. A moment code I get a force close because of the on click listener for the check box but not sure how else to implement it. Thanks in advance for any help.
Here's the code
private void dialog(){
final SharedPreferences settings = this.getSharedPreferences("MyApp",0);
boolean stillrun=settings.getBoolean("stillrun",true);
if (stillrun) {
final Dialog dialog = new Dialog(Zoom.this);
dialog.setContentView(R.layout.info);
dialog.setTitle("Using the zoom function");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(R.string.zoomtext);
Button button = (Button) dialog.findViewById(R.id.buttonClose);
button.setOnClickListener(new OnClickListener() 开发者_如何学JAVA{
public void onClick(View v) {
dialog.cancel();
}
});
CheckBox checkbox = (CheckBox) findViewById(R.id.checkBox1);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
SharedPreferences.Editor e = settings.edit();
e.putBoolean("stillrun",false);
e.commit();
}
}
});
dialog.show();
}
You read the property from "stillrun" and write to the property "firstrun" - is this what you want?
精彩评论