好的,所以我最近在這個冬季休息時間使用Eclipse進行了這個Android應用程序開發,所以請原諒我,如果這是一個非常簡單的問題。測驗應用程序 - 循環問題
我到目前爲止有一個應用程序提出問題(我在程序中創建問題),用戶鍵入答案和提交提交,非常簡單。我的問題是,如何讓應用程序進入下一個問題?以下是我迄今爲止:
package first.project;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
//import java.util.Random;
public class FirstProjectActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Champion ahri = new Champion(0, "Ahri", "I am a Mage", false);
Champion akali = new Champion(1, "Akali", "Ninja stuff", true);
Champion alistar = new Champion(2, "Alistar", "I am a cow", false);
final LinkedList champions = new LinkedList();
champions.insert(ahri);
champions.insert(akali);
champions.insert(alistar);
question = (TextView) findViewById(R.id.question);
txtname = (EditText) findViewById(R.id.txt_name);
blah = (Button) findViewById(R.id.btn_clickme);
quit = (Button) findViewById(R.id.quit);
quit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
Champion tmp;
//Random randomGenerator = new Random();
//int randomNumber = randomGenerator.nextInt(2);
//tmp = champions.find(randomNumber);
/*while (tmp.hasBeenCalled) {
randomNumber = randomGenerator.nextInt(2);
tmp = champions.find(randomNumber);
}*/
/*tmp.hasBeenCalled = true;
while (tmp.name == null) {
Toast.makeText(getBaseContext(), "You have completed the quiz!", Toast.LENGTH_SHORT);
blah.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "You have completed the quiz!", Toast.LENGTH_SHORT);
}
});
}*/
tmp = champions.getFirst();
// while (tmp.name != null); {
question.setText(tmp.says);
final Champion temp = tmp;
blah.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String str1 = txtname.getText().toString();
if (champions.isCorrect(temp.name, str1)) {
Toast.makeText(getBaseContext(), getString(R.string.correct), Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(getBaseContext(), getString(R.string.incorrect), Toast.LENGTH_SHORT).show();
}
});
//tmp.hasBeenCalled = true;
tmp = champions.getNext();
//question.setText(tmp.says);
// }
}
private EditText txtname;
private Button blah;
private Button quit;
private TextView question;
}
好了,我有一個Link
和LinkedList
和Champions
java文件和所有。我的問題是,當我嘗試循環(被註釋掉的while循環)時,它會打破應用程序,當我模擬它時什麼都不顯示。但我不知道如何將下一個問題放到頁面上。我是否必須爲每個問題創建一個屏幕?我必須一遍又一遍地寫出每個問題嗎?任何幫助表示讚賞。對不起,如果我不是很清楚。 (和代碼,即使在我編碼時,我真的是一個pac老鼠,我不想刪除代碼,直到我確信知道我不需要它)。
Ÿ不ü放在一個數據庫並加載一個所有問題後,其他? – 2011-12-29 09:15:18
我其實只是環顧四周,看到有人這樣做。我完全沒有想過這個。這只是一個教自己的Java應用程序,所以我會def試試。 – LiverpoolFTW 2011-12-29 16:03:00