Saturday, April 12, 2014

AlertDialog.Builder multi marquee Select function and anti-election


There is a checkbox Select All button, you need to realize the function is selected by Select all option is selected, deselect all options are canceled all
The current situation is, check the Select All option can be selected, but it can not cancel the Select All option to cancel the code below

String [] strArr = new String [] {"Zhao", "money", "Sun", "Lee", "week", "Miss", "Zheng", "king", "Select"};
boolean [] boolArr = new boolean [strArr.length];

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);

Button button = (Button) findViewById (R.id.button);
button.setOnClickListener (new OnClickListener () {

@ Override
public void onClick (View v) {
AlertDialog.Builder builder = new AlertDialog.Builder (MainActivity.this);
builder.setTitle ("multiple choice");
builder.setMultiChoiceItems (strArr, boolArr, new OnMultiChoiceClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which, boolean isChecked) {
if (which == strArr.length - 1) {/ / Click Select
for (int i = 0; i boolArr [i] = isChecked;
}
} Else {
boolArr [which] = isChecked;
}
}
});
builder.setPositiveButton ("OK", null);
builder.setNegativeButton ("Cancel", null);
builder.create () show ();.
}
});
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
 @ Override 
public void onClick (DialogInterface dialog, int which, boolean isChecked) {
boolean state = false ;/ / used to identify the whole election there has been a wholly-election was true
if (which == strArr.length - 1) {/ / Click Select
for (int i = 0; i if (state) {
boolArr [i] = false;
} Else {
boolArr [i] = true;
}
state = state;!
}
} Else {
boolArr [which] = isChecked;
}
}


onClick () to change a bit. The main logic here is a little wrong, not enough, then you have to do stress that the focus isChecked is true or false.
Reply:
cited a floor tantahe reply:
 @ Override 
public void onClick (DialogInterface dialog, int which, boolean isChecked) {
boolean state = false ;/ / used to identify the whole election there has been a wholly-election was true
if (which == strArr.length - 1) {/ / Click Select
for (int i = 0; i if (state) {
boolArr [i] = false;
} Else {
boolArr [i] = true;
}
state = state;!
}
} Else {
boolArr [which] = isChecked;
}
}


onClick () to change a bit. The main logic here is a little wrong, not enough, then you have to do stress that the focus isChecked is true or false.

I changed
 if (which == strArr.length - 1) {/ / Click Select 
! isAllChecked = isAllChecked;
for (int i = 0; i if (isAllChecked) {
boolArr [i] = true;
} Else {
boolArr [i] = false;
}
}
} Else {
boolArr [which] = isChecked;
}

boolean isAllChecked is a member variable, or not, debug seen, when the whole election is true, boolArr [] every one is true, the whole election is false when, boolArr [] every one is false, but true when each checkbox will be checked, and false when only Select the checkbox of the hook is removed, the other checkbox hook still
Reply:
reference to the second floor gyl31016 reply:
Quote: references to a floor tantahe reply:

 @ Override 
public void onClick (DialogInterface dialog, int which, boolean isChecked) {
boolean state = false ;/ / used to identify the whole election there has been a wholly-election was true
if (which == strArr.length - 1) {/ / Click Select
for (int i = 0; i if (state) {
boolArr [i] = false;
} Else {
boolArr [i] = true;
}
state = state;!
}
} Else {
boolArr [which] = isChecked;
}
}


onClick () to change a bit. The main logic here is a little wrong, not enough, then you have to do stress that the focus isChecked is true or false.

I changed
 if (which == strArr.length - 1) {/ / Click Select 
! isAllChecked = isAllChecked;
for (int i = 0; i if (isAllChecked) {
boolArr [i] = true;
} Else {
boolArr [i] = false;
}
}
} Else {
boolArr [which] = isChecked;
}

boolean isAllChecked is a member variable, or not, debug seen, when the whole election is true, boolArr [] every one is true, the whole election is false when, boolArr [] every one is false, but true when each checkbox will be checked, and false when only Select the checkbox of the hook is removed, the other checkbox hook still

Select when not all tick it? If not, your logic here is not that so write
if (which == strArr.length - 1) {/ / Click Select
else {
boolArr [which] = isChecked;
}
Click to cancel all the options when the settings are not selected code into the Select outside.
Reply:
Get
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=199941&_dsign=ee3d1880

No comments:

Post a Comment