Android编程权威指南(第四版)-第 2 章 Android与MVC设计模式

文章目录

  • 代码
    • MainActivity
    • Question
    • activity_main.xml
    • string.xml
  • 效果
  • 知识点

代码

大体是一样的,修改了一些

MainActivity

package com.example.geoquiz

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.TextView
import android.widget.Toast

class MainActivity : AppCompatActivity() {
   
    private lateinit var questionText: TextView
    private lateinit var ture_button: Button
    private lateinit var false_button: Button
    private lateinit var last_button: Button
    private lateinit var next_button: Button
    private var questionList = listOf(
        Question(R.string.question, true),
        Question(R.string.question1, true),
        Question(R.string.question2, true),
        Question(R.string.question3, false),
        Question(R.string.question4, false),
        Question(R.string.question5, false)
    )
    private var index = 0
    override fun onCreate(savedInstanceState: Bundle?) {
   
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        questionText = findViewById(R.id.question)
        ture_button = findViewById(R.id.ture_button)
        false_button = findViewById(R.id.false_button)
        last_button = findViewById(R.id.last_button)
        next_button = findViewById(R.id.next_button)
updateQuestion()
        //点击问题跳转下一题
        questionText.setOnClickListener(View.OnClickListener {
   
            index = (index + 1) % questionList.size
            updateQuestion()
        })

        ture_button.setOnClickListener(View

你可能感兴趣的:(android,mvc,设计模式)