MainActivity.kt 1.0 KB
package com.br_technology.securitytrain_master

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.lifecycle.Observer
import com.br_technology.securitytrain_master.databinding.ActivityMainBinding
import com.br_technology.securitytrain_master.test.TestModel
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity

class MainActivity : BaseLifeCycleActivity<TestModel,ActivityMainBinding>(ActivityMainBinding::inflate),
    View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.tvTest.setOnClickListener(this)
    }

    override fun initDataObserver() {
        mViewModel.mTestListData.observe(this, Observer { response ->
            response.let {
                binding.tvName.text = it.result[0].name
            }
        })
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.tv_test ->{
                mViewModel.getTestData()
            }
        }
    }
}