final JSONArray jsonArray = new JSONArray(response);
final Boolean[] state = new Boolean[100];//how to correctly initialize this one i added 100 because it need something. how can i turn it dynamically
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = (JSONObject) jsonArray.get(i);
String syncstatus = "";
if (obj.get("syncstatus").toString().matches("1")) {
syncstatus = "Not yet synchronized";
state[i] = false;
} else if (obj.get("syncstatus").toString().matches("2")) {
syncstatus = "Synchronized";
state[i] = true;
}
checkedsurveylist.add("(" + obj.get("sysid").toString() + ")" + obj.get("surveytitle").toString() + " - " + syncstatus);
}
final List < String > mSelectedItems = new ArrayList < String > ();
AlertDialog.Builder builder = new AlertDialog.Builder(Connect_server.this);
builder.setTitle("My Title")
.setMultiChoiceItems(checkedsurveylist.toArray(new CharSequence[checkedsurveylist.size()]), state,
new DialogInterface.OnMultiChoiceClickListener() {@
Override
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
checkedsurveylist.toArray()[which] = isChecked;
if (isChecked) {
mSelectedItems.add(checkedsurveylist.get(which).toString());
} else if (mSelectedItems.contains(which)) {
mSelectedItems.remove(Integer
.valueOf(which));
}
}
});
This is how i tried to set check status of my checkbox in alert dialog. But I get error and I run out of idea. This code gets error when I add state
to this line setMultiChoiceItems(checkedsurveylist.toArray(new CharSequence[checkedsurveylist.size()]), state, new DialogInterface.OnMultiChoiceClickListener() {
Without the state it runs ok.
How to correctly set checkbox state in alert dialog
Aucun commentaire:
Enregistrer un commentaire