代码清单2-6 增加按钮变量及Question对象数组

xiaoxiao2021-03-01  12

package com.bignerdranch.android.quize; import android.view.View; import android.widget.Button; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; public class QuizActivity extends AppCompatActivity { private Button mTrueButton; private Button mFalseButton; private Button mNextButton; private TextView mQuestionTextView; private Question[] mQuestionBank=new Question[]{ new Question(R.string.question_australia,true), new Question(R.string.question_oceans,true), new Question(R.string.question_mideast,false), new Question(R.string.question_africa,false), new Question(R.string.question_americas,true), new Question(R.string.question_asia,true) }; private int mCurrentIndex=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); mTrueButton=(Button)findViewById(R.id.true_button); mTrueButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show(); } }); mFalseButton=(Button)findViewById(R.id.false_button); mFalseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show(); } }); } }
转载请注明原文地址: https://www.6miu.com/read-3650253.html

最新回复(0)