views:

259

answers:

3

Hi,

I'm building a game which works as some type of a quiz. I ask user the question and when he submits the answer(click or touch correct answer) I need to refresh the page with some other question.

How should i implement this? How to wait for users answer and continue when onClick or OnTouch listener finishes? Should i use Handler class, intents or something else?

Thx in advance for help.

edit: I want next scenario: On the screen I have a question and 3-4 clickable ImageButtons. I'm building some of the layout dinamically from custom showQA() function. User choose the answer and if he clicked the correct answer i should start some type of animation on the screen. I've done that from the onClickListener. Now, i need to build layout again(show new question and answers) from the showQA() function which must be called after that animation showed to the user. How can i know when the onClickListener() finished its work?

+1  A: 

I think in your case one activity would be sufficient and you just place two views (question, answer) in this activity on which you switch the visibilities accordingly and update the question/answer content.

For the click/touch: depends what kind of answer the user needs to provider (enter text, click a button, use a slider, etc). But a listener would be the right thing, i.e. onClickListener for a button.

For a quiz, you probably want to implement your special logic in custom widgets that you extend from the basic ones, i.e. a button group for i.e. A) - E) answer buttons (i.e. flexible in number), etc. and abstract the game logic a bit.

But that really depends no your game details, cannot say much withough knowing the game play in detail.

Mathias Lin
Ok, in my first post I tried to simplify the scenario.On the screen I have a question and 3-4 clickable ImageButtons. I'm building some of the layout dinamically from custom showQA() function.I want next scenario:User choose the answer and if he clicked the correct answer i should start some type of animation on the screen. I've done that from the onClickListener. Now, i need to build layout again(show new question and answers) from the showQA() function which must be called after that animation showed to the user. How can i know when the onClickListener() finished its work?
Milos Pesic
at the end of the ClickListener/onClick method, you can add any code and call the method you want, i.e. showQA() if you like
Mathias Lin
A: 

Typically, the easiest way to organize your app is to start a new instance of an activity for each new view.

In your case, you might have one base activity that has a list of all of the questions.

Your ShowQuestionActivity takes in a question and list of answer choices via intent extras.

BaseActivity starts ShowQuestionActivity for result with the first question. When the user clicks on an answer, ShowQuestionActivity finishes. It can pass the answer back with an extra.

BaseActivity immediately starts ShowQuestionActivity for result with the second question. To the user, this will appear as if you just moved from one question to the next smoothly.

Alternatively, you can have each ShowQuestionActivity start the next ShowQuestionActivity, but then you need to keep track of which question to show, and all of the answers via intents.

Mayra
I understand what's your point.However, i didn't succeed to make it 'smooth'.I mean, it always shows the transition when new activity is started.I want to get same result like i just called imageView.setBackgroundResouce(R.drawable.something_else)..Here's the code i tried:Intent intent = new Intent();intent.setClass(SomeClass.this,CalledClass.class);startActivity(intent);finish();
Milos Pesic
See http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_ANIMATION
Mayra
I tried setting that flag in the intent and nothing changed. Also i tried passing it to startActivityForResult() but with no results also.I'm developing on Android 2.1 and testing on HTC Desire.
Milos Pesic
Wierd. I think you would set it on the intent. Do you have it set up as I described with finishing, and then a base activity starts the next activity? If so, you might need to set the flag on both the finishing and on the new intent?
Mayra
A: 

I've solved the problem using AnimationListener. I started the animation after user clicks the answer, and called showQA() function for creating user interface from onAnimationEnd method.

Milos Pesic