動的データを使用して、複数選択の AlertDialog を構築しようとしています。
わかりました、それはすべて素晴らしいロードなどですが、選択がめちゃくちゃです。
これが私のコードです:
new AlertDialog.Builder(this)
.setTitle("Cities")
.setMultiChoiceItems(_options, _selections, new DialogInterface.OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog, int clicked, boolean selected) {
Log.i("Database", _options[clicked] + " selected: " + selected);
}
})
.setPositiveButton("OK", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int clicked) {
switch(clicked) {
case DialogInterface.BUTTON_POSITIVE:
for( int i = 0; i < _options.length; i++ ){
Log.i("Database", "id: " + _values[i] + " " + _options[i] + " selected: " + _selections[i]);
}
break;
}
}
})
.create();
LogCat でわかるように、私の問題を説明しました。
** OPENED ALERTDIALOG VIA A BUTTON AND SELECTED THE FOLLOWING: **
07-12 16:06:51.347: I/Database(8034): Aveiro selected: true
07-12 16:06:53.936: I/Database(8034): Coimbra selected: true
07-12 16:07:00.116: I/Database(8034): Porto selected: true
** AFTER PRESSING THE OK BUTTON, THIS SHOWS UP, WHICH IS CORRECT: **
07-12 16:07:02.826: I/Database(8034): id: 1 Aveiro selected: true
07-12 16:07:02.826: I/Database(8034): id: 2 Coimbra selected: true
07-12 16:07:02.826: I/Database(8034): id: 3 Porto selected: true
07-12 16:07:02.826: I/Database(8034): id: 4 Minho selected: false
** I CLICKED THE BUTTON TO START THE DIALOG AGAIN DE UNSELECTED THE FOLLOWING: **
07-12 16:07:07.087: I/Database(8034): Coimbra selected: false
** AFTER PRESSING THE OK BUTTON, ALL SHOWS AS FALSE. 1 AND 3 SHOULD BE TRUE: **
07-12 16:07:08.097: I/Database(8034): id: 1 Aveiro selected: false
07-12 16:07:08.097: I/Database(8034): id: 2 Coimbra selected: false
07-12 16:07:08.097: I/Database(8034): id: 3 Porto selected: false
07-12 16:07:08.097: I/Database(8034): id: 4 Minho selected: false