1. Download our Official Android App: Forums for Android!

Help on an image-based quizz

Discussion in 'Android Development' started by Wakigawa, Sep 28, 2017.

  1. Wakigawa

    Wakigawa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 28, 2017

    Sep 28, 2017
    3
    0
    5
    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!
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,456
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,456
    10,741
    1,988
    Male
    Software developer
    South West of England
    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.
     
  3. Wakigawa

    Wakigawa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 28, 2017

    Sep 28, 2017
    3
    0
    5
    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.
     

    Attached Files:

  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,456
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,456
    10,741
    1,988
    Male
    Software developer
    South West of England
    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 (Text):
    1.  
    2. @Override
    3. public void onClick(View arg0) {
    4.   ...
    5. }
    6.  
    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 (Text):
    1.  
    2. Button button = (Button) findViewById(R.id.button1);
    3. button.setOnClickListener(this);
    4.  
     
  5. Wakigawa

    Wakigawa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 28, 2017

    Sep 28, 2017
    3
    0
    5
    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){
    }
    }
    });
    }

    }
     

Share This Page

Loading...