我有下一个代码,我试图根据用户选择在此方法中返回“玩家”的值。问题我可以用对话框的 onClick 方法做到这一点,知道吗?
public int dialogoInicial(){
int players = 1;
final String[] playersArray = {"1","2","3","4","5","6"};
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("Nº "+getString(R.string.players)+":");
dialog.setSingleChoiceItems(playersArray, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int player) {
players = Integer.parseInt(playersArray[player]);
}
});
dialog.show();
return players;
}