I am working on android quiz. In my code i have countdown timer when time finish i want next question came and score are decreases (for score decrement currentGame.decrement
Create a new method say processScreen()
and insert data of onCreate
inside it so that you can call this method, repeatedly with having to call same activity again..(its a workaround..)
private void processScreen(){
/**
* Configure current game and get question
*/
currentGame = ((CYKApplication)getApplication()).getCurrentGame();
currentQ = currentGame.getNextQuestion();
Button nextBtn1 = (Button) findViewById(R.id.answer1);
nextBtn1.setOnClickListener(this);
Button nextBtn2 = (Button) findViewById(R.id.answer2);
nextBtn2.setOnClickListener(this);
Button nextBtn3 = (Button) findViewById(R.id.answer3);
nextBtn3.setOnClickListener(this);
Button nextBtn4 = (Button) findViewById(R.id.answer4);
nextBtn4.setOnClickListener(this);
Button nextBtn5 = (Button) findViewById(R.id.answer5);
nextBtn5.setOnClickListener(this);
/**
* Update the question and answer options..
*/
setQuestions();
}
so now your onCreate
becomes
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question);
processScreen();
}
Now, call processScreen()
instead of calling QuestionActivity
again in onClick
of your button. In other words, contents will be refreshed..
Hope this helps..