android_checkbox_dialog设计是不是开起默认不提示
package com.example.android_checkbox_dialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class TestDialogActivity extends Activity {
private Button btn;
final Context context = this;
final String[] multiChoiceItems = {"开启默认不提示"};
final boolean[] defaultSelectedStatus = {false};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(defaultSelectedStatus[0] != true)
showDialog5();
else
Toast.makeText(context,"已经开启默认设置", Toast.LENGTH_LONG).show();
}
});
}
public void showDialog5(){
final StringBuilder sb = new StringBuilder();
new AlertDialog.Builder(context)
.setTitle("复选框")
.setMultiChoiceItems(multiChoiceItems, defaultSelectedStatus, new OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
defaultSelectedStatus[which] = isChecked;
}
})
.setPositiveButton("确定",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for(int i=0;i<defaultSelectedStatus.length;i++) {
if(defaultSelectedStatus[i]) {
sb.append(multiChoiceItems[i]);
}
}
Toast.makeText(context,sb.toString(), Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("取消", null)
.show();
}
}