Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android问答逻辑/编码_Java_Android - Fatal编程技术网

Java Android问答逻辑/编码

Java Android问答逻辑/编码,java,android,Java,Android,我用actionscript做了一个测验。我已经开始在android(完全的新手)上做测验,跟随动作脚本,以便让我的头脑绕过逻辑 我不知道如何处理change\u question函数,尤其是第一块。下面 function change_question(){ if(tick.visible){ right_answers++; } if(cross.visible){ wrong_answers++; } if(qno==questions.leng

我用actionscript做了一个测验。我已经开始在android(完全的新手)上做测验,跟随动作脚本,以便让我的头脑绕过逻辑

我不知道如何处理change\u question函数,尤其是第一块。下面

  function change_question(){
  if(tick.visible){
     right_answers++;
  }
  if(cross.visible){
     wrong_answers++;
  }
  if(qno==questions.length){
       gotoAndPlay(2);
   }else{
  tick.visible=false;
  cross.visible=false;
  rnd1=Math.ceil(Math.random()*3);
  rnd2=Math.ceil(Math.random()*questions.length)-1;
  q.text=questions[rnd2];
  if(questions[rnd2]=="x"){
  change_question();
  }
  questions[rnd2]="x";
  enable_disable(1);
任何指导都将不胜感激。提前谢谢


这是我到目前为止的android代码

package ks3.mathsapp.project;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
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;


    int qno = 0;
    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);
    cross = (ImageView) findViewById(R.id.cross);
    tick = (ImageView) findViewById(R.id.tick);

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



        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]) ;  
        }


    }


    }   

这是我用来帮助理解逻辑的动作脚本模型

  var qno=0;var rnd1; var rnd2;
  tick.visible=false;cross.visible=false;
  var right_answers=0;var wrong_answers=0;

  function change_question(){
  if(tick.visible){
     right_answers++;
  }
  if(cross.visible){
     wrong_answers++;
  }
  if(qno==questions.length){
       gotoAndPlay(2);
   }else{
  tick.visible=false;
  cross.visible=false;
  rnd1=Math.ceil(Math.random()*3);
  rnd2=Math.ceil(Math.random()*questions.length)-1;
  q.text=questions[rnd2];
  if(questions[rnd2]=="x"){
  change_question();
  }
  questions[rnd2]="x";
  enable_disable(1);

  if(rnd1==1){opt1.text=answers[rnd2][0];opt2.text=answers[rnd2][1];opt3.text=answers[rnd2][2];opt4.text=answers[rnd2][3];} 
  if(rnd1==2){opt1.text=answers[rnd2][2];opt2.text=answers[rnd2][0];opt3.text=answers[rnd2][1];opt4.text=answers[rnd2][3];} 
  if(rnd1==3){opt1.text=answers[rnd2][1];opt2.text=answers[rnd2][2];opt3.text=answers[rnd2][0];opt4.text=answers[rnd2][3];} }} 

  function enable_disable(a){ 
  if(a==0)   {shade1.mouseEnabled=false;shade2.mouseEnabled=false;shade3.mouseEnabled=false;shade4.mouseEnabled=false;} 
  if(a==1){shade1.mouseEnabled=true;shade2.mouseEnabled=true;shade3.mouseEnabled=true;shade4.mouseEnabled=true;}}

change_question();

next_b.addEventListener(MouseEvent.CLICK, ButtonAction1); 
function ButtonAction1(eventObject:MouseEvent) {qno++;change_question();} 

shade1.addEventListener(MouseEvent.CLICK, ButtonAction2); 
shade2.addEventListener(MouseEvent.CLICK, ButtonAction3); 
shade3.addEventListener(MouseEvent.CLICK, ButtonAction4);
shade4.addEventListener(MouseEvent.CLICK, ButtonAction5);

 function ButtonAction2(eventObject:MouseEvent){enable_disable(0);if(rnd1==1){      tick.visible=true;tick.y=shade1.y}else{cross.visible=true;cross.y=shade1.y}}
 function ButtonAction3(eventObject:MouseEvent){enable_disable(0);if(rnd1==2){tick.visible=true;tick.y=shade2.y}else{cross.visible=true;cross.y=shade2.y}}
 function ButtonAction4(eventObject:MouseEvent){enable_disable(0);if(rnd1==3){tick.visible=true;tick.y=shade3.y}else{cross.visible=true;cross.y=shade3.y}}
 function ButtonAction5(eventObject:MouseEvent){enable_disable(0);if(rnd1==4){tick.visible=true;tick.y=shade4.y}else{cross.visible=true;cross.y=shade4.y}}


stop();
我会给你几点意见(我会在我做的时候把它们编辑成这个答案,绝对没有逻辑顺序)

  • 定义个人
    rnd
    s时,请在成员
    TextView[]
    中设置问题。通过这种方式,您不需要调用多少
    findViewById()
    ,如果您了解java中的函数,这将为您节省大量代码

  • shade1.addEventListener(MouseEvent.CLICK,ButtonAction2)将成为

    shade1.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            buttonAction2();
        }
    };
    
  • 您找到了
    setVisibility()
    getVisibility()
    ,如果您只想在其他元素上禁用onClick事件,可以使用
    setEnabled(true | false)


希望这能帮助你前进。

哦,天哪!你总是这样写代码吗?换行和缩进怎么样?对不起,我做了一些修改。希望这能让它更容易阅读。很难全部复制。谢谢sam,我又开始编写代码了。我很快会在主要问题中公布我所做的事情。谢谢