ITPub博客

首页 > 应用开发 > IT综合 > 问题描述已经分离在资源文件中,如何将answer也分离在资源文件中?

问题描述已经分离在资源文件中,如何将answer也分离在资源文件中?

原创 IT综合 作者:634828354 时间:2017-04-12 20:13:39 0 删除 编辑

 1)修改strings.xml

  <string name="question_oceans">1The Pacific Ocean is larger than the Atlantic Ocean</string>

  <string name="question_mideast">2The Suez Canal connects the Red Sea and the Indian Ocean</string>

  <string name="question_africa">3the source of the nile River is in Egypt</string>

  <string name="question_americas"> 4the amazon river is the longest river in the USA</string>

  <string name="question_asia">5Lake Baikal is the world\'s oldest and deepest freshwater lake</string>

  <string name="correct_toast">Correct</string>

  <string name="incorrect_toast">Incorrect</string>

 

  2)修改按钮监听方法

  mFalseButton=(Button)findViewById(R.id.false_button);

  mFalseButton.setOnClickListener(new View.OnClickListener(){

 

    @Override

    public void onClick(View view) {

        checkAnswer(false);

    }

  });

  mNextButton = (Button)findViewById(R.id.next_button);

  mNextButton.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {

        mCurrentIndex=(mCurrentIndex+1)%mQuestionsBank.length;

        updateQuestion();

    }

  });

  3)增加checkAnswer方法

  private void checkAnswer(boolean userPressedTrue){

    boolean answerIsTrue =mQuestionsBank[mCurrentIndex].isAnswerTrue();

    int messageResId=0;

    if (userPressedTrue==answerIsTrue){

        messageResId=R.string.correct_toast;

    }else{

        messageResId=R.string.incorrect_toast;

    }

    Toast.makeText(this,messageResId,Toast.LENGTH_SHORT).show();

  }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30046312/viewspace-2137135/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-12-01

  • 博文量
    47
  • 访问量
    96785