重复答案问答游戏

时间:2018-10-07 14:54:26

标签: image duplicates

我是一名初学者,我想用图像而不是问题进行测验。测验工作正常,但按钮上有重复的答案。 例如enter image description here。我不知道该怎么办,我认为这对认识的人来说非常简单。您知道我该如何解决吗?非常感谢!

enter image description here

Graph = facebook.GraphAPI(access_token=token, version="3.0")
profile = graph.get_object('me')
posts = graph.get_connections("me", "likes")
print(len(posts['data']))

公共类picitem {

package com.example.tolis.a123;






@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    r = new Random();

    iv_Pic = (ImageView) findViewById(R.id.iv_Pic);
    b_answer1 = (Button)findViewById(R.id.b_answer1);
    b_answer2 = (Button) findViewById(R.id.b_answer2);
    b_answer3 = (Button) findViewById(R.id.b_answer3);
    b_answer4 = (Button) findViewById(R.id.b_answer4);

    list = new ArrayList<>();

    for(int i = 0; i < new database().emotions.length; i++){
      list.add(new picitem(new database().answers[i], new database().emotions[i]));

   }

    Collections.shuffle(list);
    newQ(quizCount);



    b_answer1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //check if the answer is correct
            if(b_answer1.getText().toString().equalsIgnoreCase(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"Correct", Toast.LENGTH_SHORT).show();
                rightAnswerCount++;

                //check if is the last question
                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);
                } else

                {
                    Intent results = new Intent(getApplicationContext(),Category1.class);
                    results.putExtra("RightAnswerCount",rightAnswerCount);
                    startActivity(results);
                }
            }else if(b_answer1.getText()!=(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"wrong",Toast.LENGTH_SHORT).show();

                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);

                }
            }
        }
    });
    b_answer2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //check if the answer is correct
            if(b_answer2.getText().toString().equalsIgnoreCase(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"Correct", Toast.LENGTH_SHORT).show();
                rightAnswerCount++;

                //check if is the last question
                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);
                } else

                {
                    Intent results = new Intent(getApplicationContext(),Category1.class);
                    results.putExtra("RightAnswerCount",rightAnswerCount);
                    startActivity(results);
                }
            }else if(b_answer2.getText()!=(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"wrong",Toast.LENGTH_SHORT).show();

                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);

                }
            }
        }
    });
    b_answer3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //check if the answer is correct
            if(b_answer3.getText().toString().equalsIgnoreCase(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"Correct", Toast.LENGTH_SHORT).show();
                rightAnswerCount++;

                //check if is the last question
                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);
                } else

                {
                    Intent results = new Intent(getApplicationContext(),Category1.class);
                    results.putExtra("RightAnswerCount",rightAnswerCount);
                    startActivity(results);
                }
            }else if(b_answer3.getText()!=(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"wrong",Toast.LENGTH_SHORT).show();

                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);

                }
            }
        }
    });
    b_answer4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //check if the answer is correct
            if(b_answer4.getText().toString().equalsIgnoreCase(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"Correct", Toast.LENGTH_SHORT).show();
                rightAnswerCount++;

                //check if is the last question
                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);
                } else

                {
                    Intent results = new Intent(getApplicationContext(),Category1.class);
                    results.putExtra("RightAnswerCount",rightAnswerCount);
                    startActivity(results);
                }
            }else if(b_answer4.getText()!=(list.get(quizCount - 1).getName())){
                Toast.makeText(Test.this,"wrong",Toast.LENGTH_SHORT).show();

                if(quizCount < list.size()) {
                    quizCount++;
                    newQ(quizCount);

                }
            }
        }
    });
}



private void newQ(int number) {
    iv_Pic.setImageResource(list.get(number - 1).getImage());
    //deceide which answer is correct
        int correct_answer = r.nextInt(4)+1  ;

            int firstButton = number - 1;
            int secondButton ;
            int thirdButton;
            int forthButton;


            switch (correct_answer) {
                case 1:
                    b_answer1.setText(list.get(firstButton).getName());
                    do {
                        secondButton = r.nextInt(list.size());
                    } while (secondButton == firstButton);
                    do {
                        thirdButton = r.nextInt(list.size());
                    } while (thirdButton == firstButton || thirdButton == secondButton);
                    do {
                        forthButton = r.nextInt(list.size());
                    }
                    while (forthButton == firstButton || forthButton == secondButton || forthButton == thirdButton);

                    b_answer2.setText(list.get(secondButton).getName());
                    b_answer3.setText(list.get(thirdButton).getName());
                    b_answer4.setText(list.get(forthButton).getName());

                    break;

                case 2:
                    b_answer2.setText(list.get(firstButton).getName());
                    do {
                        secondButton = r.nextInt(list.size());
                    } while (secondButton == firstButton);
                    do {
                        thirdButton = r.nextInt(list.size());
                    } while (thirdButton == firstButton || thirdButton == secondButton);
                    do {
                        forthButton = r.nextInt(list.size());
                    }
                    while (forthButton == firstButton || forthButton == secondButton || forthButton == thirdButton);

                    b_answer1.setText(list.get(secondButton).getName());
                    b_answer3.setText(list.get(thirdButton).getName());
                    b_answer4.setText(list.get(forthButton).getName());

                    break;

                case 3:
                    b_answer3.setText(list.get(firstButton).getName());
                    do {
                        secondButton = r.nextInt(list.size());
                    } while (secondButton == firstButton);
                    do {
                        thirdButton = r.nextInt(list.size());
                    } while (thirdButton == firstButton || thirdButton == secondButton);
                    do {
                        forthButton = r.nextInt(list.size());
                    }
                    while (forthButton == firstButton || forthButton == secondButton || forthButton == thirdButton);

                    b_answer2.setText(list.get(secondButton).getName());
                    b_answer1.setText(list.get(thirdButton).getName());
                    b_answer4.setText(list.get(forthButton).getName());

                    break;

                case 4:
                    b_answer4.setText(list.get(firstButton).getName());
                    do {
                        secondButton = r.nextInt(list.size());
                    } while (secondButton == firstButton);
                    do {
                        thirdButton = r.nextInt(list.size());
                    } while (thirdButton == firstButton || thirdButton == secondButton);
                    do {
                        forthButton = r.nextInt(list.size());
                    }
                    while (forthButton == firstButton || forthButton == secondButton || forthButton == thirdButton);

                    b_answer2.setText(list.get(secondButton).getName());
                    b_answer3.setText(list.get(thirdButton).getName());
                    b_answer1.setText(list.get(forthButton).getName());

                    break;

            }

}}





package com.example.tolis.a123;


  Integer[] emotions =  {
        R.drawable.sad,
        R.drawable.sadd,
        R.drawable.saddd,
        R.drawable.sadddd,
        R.drawable.saddddd,
        R.drawable.sadddddd,
        R.drawable.happy,
        R.drawable.happyy,
        R.drawable.happyyy,
        R.drawable.happyyyy,
        R.drawable.angry,
        R.drawable.angryy,
        R.drawable.angryyy,
        R.drawable.angryyyy,
        R.drawable.angryyyyy,
        R.drawable.fear,
        R.drawable.fearr,


};


 String  answers[] =   {
        "sad",
         "sad",
         "sad",
         "sad",
         "sad",
         "sad",
        "happy",
         "happy",
         "happy",
         "happy",
        "angry",
         "angry",
         "angry",
         "angry",
         "angry",
        "fear",
         "fear"

};






package com.example.tolis.a123;

}

0 个答案:

没有答案