いくつかの警告ダイアログを表示したいので、ユーザーはいくつかの質問を処理する必要があります (ウィザードのように)。
ユーザーが何かを選択し、選択した値を返すまで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 のオプションの 1 つを選択するまで待機する必要があります。
これは可能ですか?
このような:
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)