我想知道如何从列表中的对话框中存储选中的项目?正如您所见,我已经启动并运行了对话框,但我无法弄清楚如何将已检查的项目存储在LIST中。我不确定哪个列表或ArrayList更好,所以如果您对此有任何建议,请告诉我。
final String[] typeOfTransport =
{
"Bus",
"Pedestrian",
"Car",
"Tram",
"Bicycle",
};
final boolean[] itemsChecked = new boolean[typeOfTransport.length];
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle("Select your transport:");
dialogBuilder.setMultiChoiceItems(typeOfTransport, itemsChecked, new DialogInterface.OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
itemsChecked[which] = isChecked;
}
});
dialogBuilder.setPositiveButton("Set", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which)
{
String selectetdVal = " ";
for (int i = 0; i < typeOfTransport.length; i++)
{
if (itemsChecked[i])
{
selectetdVal = selectetdVal + typeOfTransport[i]+ " ";
itemsChecked[i]=false;
}
}
//textBox2.setText(selectetdVal);
Toast.makeText(MainWindow.this, selectetdVal,Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
检查文档,List是一个界面。 您已经有一个包含已检查项目的数组吗?
Object[] array = new Object[]{"12","23","34"};
java.util.List list = Arrays.asList(array);