安卓面试

在kotlin中如何使用BaseRecyclerViewAdap

2020-03-17  本文已影响0人  飞指

为了更好的进行理解先来对比下
Java代码

public class WithdrawRecordAdapter2 extends BaseQuickAdapter<TestWithdrawalRecordBena, BaseViewHolder> {

    public WithdrawRecordAdapter2(int layoutResId, @Nullable List<TestWithdrawalRecordBena> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TestWithdrawalRecordBena item) {
        TextView status = helper.getView(R.id.withdraw_state);
        helper.setText(R.id.withdraw_number, "-¥" + item.getMoney()).setText(R.id.withdraw_date, item.getDate());
        if (item.getState() == 1) {
            status.setText("提现中");
            status.setTextColor(Color.parseColor("#1A66FF"));

        } else if (item.getState() == 0) {
            status.setText("已提现");
            status.setTextColor(Color.parseColor("#3DC637"));
        } else if (item.getState() == -1) {
            status.setText("未通过");
            status.setTextColor(Color.parseColor("#FF661A"));
        }
    }
}

Kotlin代码

class WithdrawRecordAdapter2(layoutResId: Int, data: List<TestWithdrawalRecordBena?>?) : BaseQuickAdapter<TestWithdrawalRecordBena, BaseViewHolder>(layoutResId, data) {
    override fun convert(helper: BaseViewHolder, item: TestWithdrawalRecordBena) {
        val status = helper.getView<TextView>(R.id.withdraw_state)
        helper.setText(R.id.withdraw_number, "-¥" + item.money).setText(R.id.withdraw_date, item.date)
        if (item.state == 1) {
            status.text = "提现中"
            status.setTextColor(Color.parseColor("#1A66FF"))
        } else if (item.state == 0) {
            status.text = "已提现"
            status.setTextColor(Color.parseColor("#3DC637"))
        } else if (item.state == -1) {
            status.text = "未通过"
            status.setTextColor(Color.parseColor("#FF661A"))
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读