2012-04-16 10 views
0

私はこのクイズを少しでもやってきましたが、質問と答えを一致させるのに苦労しています。配列からの値を表示

答えを表示するはずの次の行と実際には、「[ljava.lang.string; @ 40585b18」と若干のバリエーションが表示されます。

明らか
quesAns4.setText("4) " + answers[0][3]); 

私は答えが質問に一致させたいと上記の方法は唯一だから、配列

{"3","5","8","9"} 

から8を表示:iが上になりました行を変更しようとしている

quesAns4.setText("4) " + answers[3]) ; 

基本的には、それぞれの質問の変更のために私はそれらが一致するようにしたい。質問が「秒で、300km/hで走行するときにF1カーが停止するのにどれくらい時間がかかりますか?」表示される可能性のある回答は4,6,8,10などとなります。

ありがとうございます。ありがとうございます。

以下の完全なコード!

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.TextView; 



public class MathsMultiplicationActivity extends Activity { 


TextView quesnum; 
TextView ques; 
TextView anst; 
TextView ans1; 
TextView ans2; 
TextView ans3; 
TextView ans4; 
ImageView cross; 
ImageView tick; 
Button nxt; 

    int qno = 1; 
    int right_answers = 0; 
    int wrong_answers = 0; 
    int rnd1; 
    int rnd2; 

    String [] questions = {"How much mph does the F-Duct add to the car?", 
       "What car part is considered the biggest performance variable?", 
       "What car part is designed to speed up air flow at the car rear?", 
       "In seconds, how long does it take for a F1 car to stop when travelling at 300km/h?", 
       "How many litres of air does an F1 car consume per second?", 
       "What car part can heavily influence oversteer and understeer?", 
       "A third of the cars downforce can come from what?", 
       "Around how much race fuel would be consumed per 100km?","The first high nose cone was introduced when?", 
       "An increase in what, has led to the length of exhaust pipes being shortened drastically?"}; 

    String [] [] answers = {{"3","5","8","9"}, 
    {"Tyres","Front Wing","F-Duct","Engine"}, 
    {"Diffuser","Suspension","Tyres","Exhaust"}, 
    {"4","6","8","10"}, 
    {"650","10","75","450"}, 
    {"Suspension","Tyres","Cockpit","Chassis"}, 
    {"Rear Wing","Nose Cone","Chassis","Engine"}, 
    {"75 Litres","100 Litres","50 Litres","25 Litres"}, 
    {"1990","1989","1993","1992"}, 
    {"Engine RPM","Nose Cone Lengths","Tyre Size","Number of Races"}}; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.multiplechoice); 

    // Importing all assets like buttons, text fields 
    quesnum = (TextView) findViewById(R.id.questionNum); 
    ques = (TextView) findViewById(R.id.question); 
    anst = (TextView) findViewById(R.id.answertit); 
    ans1 = (TextView) findViewById(R.id.answer1); 
    ans2 = (TextView) findViewById(R.id.answer2); 
    ans3 = (TextView) findViewById(R.id.answer3); 
    ans4 = (TextView) findViewById(R.id.answer4); 
    nxt = (Button) findViewById(R.id.btnNext); 
    cross = (ImageView) findViewById(R.id.cross); 
    tick = (ImageView) findViewById(R.id.tick); 

    cross.setVisibility(View.GONE); 
    tick.setVisibility(View.GONE); 


    quesnum.setText("Question: " + qno + "/10"); 


    final Button buttonAbout = (Button) findViewById(R.id.btnNext); 
    buttonAbout.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
     next(); 
     } 

     private void next() { 
      qno++; 
      change_question(); 
     } 

     private void change_question() { 
      if(tick.getVisibility() == View.VISIBLE){ 
       right_answers++; 
      } 

      if(cross.getVisibility() == View.VISIBLE){ 
       wrong_answers++; 
      } 
      if(qno==questions.length){ 

      }else{ 
       cross.setVisibility(View.GONE); 
       tick.setVisibility(View.GONE); 
       rnd1 = (int)Math.ceil(Math.random()*3); 
       rnd2 = (int)Math.ceil(Math.random()*questions.length)-1; 
       ques.setText(questions[rnd2]); 
       if(questions[rnd2]=="x") 
       { 
        change_question(); 
       } 
      } 
      questions[rnd2]="x"; 




      if(rnd1==1){ 
       TextView quesAns1 = (TextView) findViewById(R.id.answer1); 
       quesAns1.setText("1) " + answers[0]) ;    

       TextView quesAns2 = (TextView) findViewById(R.id.answer2); 
       quesAns2.setText("2) " + answers[1]) ; 

       TextView quesAns3 = (TextView) findViewById(R.id.answer3); 
       quesAns3.setText("3) " + answers[2]) ; 

       TextView quesAns4 = (TextView) findViewById(R.id.answer4); 
       quesAns4.setText("4) " + answers[3]) ; 
      } 

      if(rnd1==2){ 
       TextView quesAns1 = (TextView) findViewById(R.id.answer1); 
       quesAns1.setText("1) " + answers[2]) ;    

       TextView quesAns2 = (TextView) findViewById(R.id.answer2); 
       quesAns2.setText("2) " + answers[0]) ; 

       TextView quesAns3 = (TextView) findViewById(R.id.answer3); 
       quesAns3.setText("3) " + answers[1]) ; 

       TextView quesAns4 = (TextView) findViewById(R.id.answer4); 
       quesAns4.setText("4) " + answers[3]) ; 
      } 
      if(rnd1==3){ 
       TextView quesAns1 = (TextView) findViewById(R.id.answer1); 
       quesAns1.setText("1) " + answers[1]) ;    

       TextView quesAns2 = (TextView) findViewById(R.id.answer2); 
       quesAns2.setText("2) " + answers[2]) ; 

       TextView quesAns3 = (TextView) findViewById(R.id.answer3); 
       quesAns3.setText("3) " + answers[0]) ; 

       TextView quesAns4 = (TextView) findViewById(R.id.answer4); 
       quesAns4.setText("4) " + answers[3]) ; 
      } 

     } 


    }); 


    //Answer 1 click functions 
    ans1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      ans1Action(); 
     } 

     private void ans1Action() { 
      //enable_disable(0); 
      if(rnd1==1){ 
       tick.setVisibility(View.VISIBLE); 
      }else{ 
       cross.setVisibility(View.VISIBLE); 
      } 

     } 

    }); 


    //Answer 2 click functions 
    ans2.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      ans2Action(); 
     } 

     private void ans2Action() { 
      //enable_disable(0); 
      if(rnd1==2){ 
       tick.setVisibility(View.VISIBLE); 
      }else{ 
       cross.setVisibility(View.VISIBLE); 
      } 

     } 

    }); 


    //Answer 3 click functions 
    ans3.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      ans3Action(); 
     } 

     private void ans3Action() { 
      //enable_disable(0); 
      if(rnd1==3){ 
       tick.setVisibility(View.VISIBLE); 
      }else{ 
       cross.setVisibility(View.VISIBLE); 
      } 

     } 

    }); 

    //Answer 4 click functions 
    ans4.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      ans4Action(); 
     } 

     private void ans4Action() { 
      //enable_disable(0); 
      if(rnd1==4){ 
       tick.setVisibility(View.VISIBLE); 
      }else{ 
       cross.setVisibility(View.VISIBLE); 
      } 

     } 

    }); 
} 



} 

答えて

0

この:

quesAns4.setText("4) " + answers[0][3]); 

動作するかどうかこれは第1の質問です。

quesAns4.setText("4) " + answers[questionNumber][3]); 

ご質問がで起動した場合:

何をすべきことは、あなたがテキストを設定する場合は、使用、change_question(int questionNumber)

次にパラメータにchange_question機能で質問の数を持つことです0. それ以外の場合:

quesAns4.setText("1) " + answers[questionNumber-1][0]); 
quesAns4.setText("2) " + answers[questionNumber-1][1]); 
quesAns4.setText("3) " + answers[questionNumber-1][2]); 
quesAns4.setText("4) " + answers[questionNumber-1][3]); 
+0

私はこの問題を解決しました。私はちょうどrnd2 intを使用しなければなりませんでした--- change_question(rnd2)---- --- quesAns4.setText( "4)" + answers [rnd2] [3]); ---- ありがとう – ManWithNoName

0

ユーザーフレンドリーな方法で配列を印刷するには、配列項目にわたってループ処理を必要とするか、またはあなたがArrays.deepToString methodを使用することができます。

String yourPrinterFriendlyArray = Arrays.deepToString(answers[0]); 
quesAns4.setText("4) " + yourPrinterFriendlyArray); 
関連する問題