kotlin学习笔记之——写一个完整类

Kotlin的类怎么写?

Kotlin怎么继承一个类?

Kotlin怎么描述跳转方法launch()?

Kotlin怎么利用intent传值?

Kotlin怎么获取EditText的值?

以下写一个完整的类实现了上面的问题:

、、、
class AddUserDeliveryRemarkActivity : BaseNotifityActivity() {

companion object {
    fun launch(context: Context, user_id: Int?, order_id: Int?) {
        val intent = Intent(context, AddUserDeliveryRemarkActivity::class.java)
        intent.putExtra("user_id", user_id)
        intent.putExtra("order_id", order_id)
        context.startActivity(intent)
    }
}

private var lableAdapter: UserDeliveryRemarkLableAdapter? = null
private var recyclerViewLable: RecyclerView? = null
private val mData = ArrayList()
private var score = 5

override fun getContentLayout(): Int {
    return R.layout.activity_add_user_delivery_remark
}

override fun initView() {
    var lable = this.resources.getStringArray(R.array.arrayUserDeliveryRemarkList)
    for (i in lable.indices) {
        val bean = HomeMeunBean(lable[i])
        mData.add(bean)
    }
    recyclerViewLable = findViewById(R.id.recyclerViewLable) as RecyclerView
    recyclerViewLable?.layoutManager = GridLayoutManager(mContext, 3)
    lableAdapter = UserDeliveryRemarkLableAdapter()
    recyclerViewLable?.adapter = lableAdapter
    lableAdapter!!.setNewData(mData)

    //确定按钮
    val btnSubmit = findViewById(R.id.btnSubmit)
    val etContent = findViewById(R.id.etContent) as EditText

    //Adapter 点击事件
    lableAdapter?.setOnItemClickListener { adapter, view, position ->
        lableAdapter?.setPosition(position)
        score = mData.size - position
    }

    //按钮 点击事件
    btnSubmit.setOnClickListener{
        addUserDeliveryRemark(score, etContent.text.toString())
    }
}

/**
 * 添加用户备注
 */
private fun addUserDeliveryRemark(score: Int, delivery_remark: String) {
    showLoading()
    mCall = AppData.addUserDeliveryRemark(intent.getIntExtra("order_id", 0), intent.getIntExtra("user_id", 0), score, delivery_remark, object : CallBackAdapter {

        override fun onSuccess(`object`: String?) {
            ToastUtils.showShort("添加成功")
            finish()
        }

        override fun onFailure(code: Int, message: String?) {
            ToastUtils.showShort(message)
        }

        override fun onCompleted() {
            cancelLoading()
        }
    })
}

/**
 * 活动回收前应该收起键盘
 */
override fun finish() {
    KeyboardUtils.hideSoftInput(this)
    super.finish()
}}

、、、

你可能感兴趣的:(kotlin学习笔记之——写一个完整类)