In my application I have implemented a button where pressing it shows a dialog with options to choose. These options are dynamic, that is to say, they are never going to be the same amount of options, because this makes it difficult for me to detect when one is chosen.
What I thought to solve the situation was the switch assign the amount of case necessary using the value of a cycle for , doing so gives me an error, when I put the pointer over case gives me this error Case statement outside switch .
Image showing the dialog
Used code:
btn_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] item = text.split("\[")[1].split("\]")[0].split(",");
AlertDialog.Builder di = new AlertDialog.Builder(MainActivity.this);
di.setItems(item, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
for (int i = 0; i < item.length; i++) {
case i: {
Toast.makeText(MainActivity.this, "Select " + item[i], Toast.LENGTH_SHORT).show();
break;
}
}
}
}
});
di.show();
}
});
My question is: how could I solve this error or know if there is a better way to do this than I need ..