• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help on an image-based quizz

Wakigawa

Lurker
Hey guys! I just started learning to program, and i'm cracking my head over this one.
A veterinary friend asked me to help him build an app that helps identify cow sanguine groups
The idea is basically the following: 2 questions, and the choices are images (6 to be precise).

Let's call them Cow A, Cow B, Cow C, Cow D, Cow E, Cow F And in the second question Cow 1, Cow 2, (...) Cow 6
The logic is basically this:
If you choose Cow A in the first question, and Cow 2 in the second question, you'll get a 1/4 sanguinary group cow as a result
If you choose Cow B in the first question, and Cow 1 in the second question, you'll get nothing and will be prompted to start again.
And so it goes on

Now, i've designed the page layout but i have no idea how to proceed with this. Any help? Thanks!
 
Hi, welcome to the forum. Can you be more specific on the area you need help with? It may help to clarify things if you include a layout/screen design or screen shot to illustrate your UI.
 
Sure! Here it is. This activity will run 2 times, and depending on the combinations it will prompt the user to re-do the test since it's not a valid possiblity, or present the resulting cow breed from the combination.
 

Attachments

  • Sem título.png
    Sem título.png
    39 KB · Views: 110
Your first aim is to understand how Button clicks are handled.
You can make your Activity class implement the interface OnClickListener. It must then provide a method called onClick()

Code:
@Override
public void onClick(View arg0) {
  ...
}

This turns your Activity into a Button click listener. To tell the buttons to use this as the listener, you'd do something like this

Code:
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(this);
 
I've got that part done already, i'm just struggling with the logic. So far my code looks like this
The question library
package wakigawaapps.girolanda;


public class QuestionLibrary {

private String mQuestions [] = {
"Escolha a orelha",
"Escolha o perfil da cabeça.",

};


private String mChoices [][] = {
{"cow1","cow2", "cow3", "cow4", "cow5", "cow6"}
{"cowa","cowb", "cowc", "cowd", "cowe", "cowf"}
};

public String getQuestion(int a) {
String question = mQuestions[a];
return question;
}

public String getChoice1(int a) {
String choice0 = mChoices[a][0];
return choice0;
}
public String getChoice2(int a) {
String choice1= mChoices[a][1];
return choice1
}

public String getChoice3(int a){
String choice2= mChoices[a][2];
return choice2;
}

public String getChoice4(int a){
String choice3= mChoices[a][3];
return choice3;
}

public String getChoice5(int a){
String choice4 = mChoices[a][4];
return choice4;
}

public String getChoice6{int a){
String choice5 = mChoices[a][5];
return choice5;
}


Now i'm stuck with this on my activity.

package wakigawaapps.girolanda;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class test extends AppCompatActivity {
private QuestionLibrary mQuestionLibrary = new QuestionLibrary();
private TextView mQuestionView;
private Button mBchoice1;
private Button mBchoice2;
private Button mBchoice3;
private Button mBchoice4;
private Button mBchoice5;
private Button mBchoice6;
private String mAnswer;
private int mQuestionNumber = 0;
private int a;



@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_test);

mQuestionView = (TextView)findViewById(R.id.question);
mBchoice1 = (Button)findViewById(R.id.choice1);
mBchoice2 = (Button)findViewById(R.id.choice2);
mBchoice3 = (Button)findViewById(R.id.choice3);
mBchoice4 = (Button)findViewById(R.id.choice4);
mBchoice5 = (Button)findViewById(R.id.choice5);
mBchoice6 = (Button)findViewById(R.id.choice6);

mBchoice1.setOnClickListener(new View.OnClickListener(){
@override
public void onClick(View view){
}
}
});
}

}
 
Back
Top Bottom