我想展示一些警报对话框,所以用户必须处理一些问题(有点像向导)。
是否可以让 alertDialog 等到用户选择某些内容然后返回选择的值?
HashMap<Integer, Question> questions = DataConnector.getCallQuestions(position);
int nextQuestion = position;
while(nextQuestion != 0){
Question question = questions.get(nextQuestion);
CharSequence[] items = (String[])question.getAnswers();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(question.getQuestion());
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
AlertDialog alert = builder.create();
//I would like to do something like this:
nextQuestion = alert.getClickedItem();
}
编辑。回复克里斯:
程序的执行应该等到用户选择 alertDialog 中的选项之一
这可能吗?
像这样:
private int answer = 0;
....
...methode(){
//show dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(question.getQuestion());
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
CallHandleMenu.this.answer = item; //setting answer
}
});
builder.create().show();
//Here I need to know the answer (the answer should not be 0 here)