我想設置一個問答對話框,它會詢問幾個問題並存儲同樣多的答案。當我通過QuestionsAnswer.java
傳遞一個int時,它將設置@string/questions[i]
和@string/answers[i]
。我試圖通過在這裏搜索和java的文檔找到我的答案,沒有運氣。單個java switch語句返回2個變量
僞代碼:
public class QuestionAnswer {
public static void QuestionAnswer(int QuestionNum) {
String question;
String answer;
switch (QuestionNum) {
case 1: question = "What are you doing?", answer = "activity";
break;
case 2: question = "Where have you been?", answer = "Location";
break;
case 3: question = "Are you looking at me?", answer = "Boolean";
break;
case 4: question = "What do you think about when I'm not around?", answer = "Crazy";
break;
case 5: question = "Do you want to play a game?", answer = "MovieQuote";
break;
case 6: question = "Does a cat have nine lives?", answer = "CanCatsFly";
break;
}
//question is a string variable that will change the question text for the dialog
R.string.Questions = question;
//answer is a string variable that will change what column name the answer will be stored into
R.string.answers = answer;
}
}
下面是編輯後的漢化版。它完美的工作! 公共類問題答案{
public static void QuestionAnswer(int QuestionNum) {
String question;
String answer;
switch (QuestionNum) {
case 1: question = "What are you doing?";
answer = "activity";
break;
case 2: question = "Where have you been?";
answer = "Location";
break;
case 3: question = "Are you looking at me?";
answer = "Boolean";
break;
case 4: question = "What do you think about when I'm not around?";
answer = "Crazy";
break;
case 5: question = "Do you want to play a game?";
answer = "MovieQuote";
break;
case 6: question = "Does a cat have nine lives?";
answer = "CanCatsFly";
break;
}
//question is a string variable that will change the question text for the dialog
R.string.Questions = question;
//answer is a string variable that will change what column name the answer will be stored into
R.string.answers = answer;
}
}
你的僞代碼應工作,只是用smicolon替換逗號('')(';')... –
把它全部扔掉,並使用某種表格。 – EJP
我討厭語法錯誤哈哈......但它現在很好用!謝謝! –