滚动时间选择器recyclerview_android - 尝试使用RecyclerView创建时间选择器 - SO中文参考 - www.soinside.com...

早安,所以我现在正在学习,我想创建一个时间选择器,但在适配器支架上遇到了问题

如何将所选开始时间的背景颜色更改为结束时间class TimeAdapter constructor(

listTime: MutableList,

mainActivity: MainActivity

) : RecyclerView.Adapter() {

private val TAG = "TimeAdapter"

private val timeList : MutableList = listTime

private val main = mainActivity

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {

val itemView = LayoutInflater.from(parent.context)

.inflate(R.layout.layout_item_time_select, parent, false)

return ItemViewHolder(itemView)

}

override fun getItemCount(): Int {

return timeList.size

}

override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {

if (timeList[position].timeTitle == null){

holder.mTitle.visibility = View.INVISIBLE

}

holder.mTitle.text = timeList[position].timeTitle

holder.timeQuarter.setOnClickListener {

main.updateArrayIfSelected(position)

timeList.forEach {

Log.d(TAG,"Position $it" + " " + it.isThisSelected.toString())

}

timeList.forEach {

if(it.isThisSelected == true){

holder.timeQuarter.setBackgroundColor(main.resources.getColor(R.color.time_select_color))

}

}

}

}

class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

var mTitle: TextView = itemView.findViewById(R.id.time_title)

var timeQuarter: View = itemView.findViewById(R.id.time_quarter)

// var firstQuarter: View = itemView.findViewById(R.id.firstQuarter)

// var secondQuarter: View = itemView.findViewById(R.id.secondQuarter)

}

}[输入,我单击了8:00 am和9:00 am

我的代码当前输出

我想要的输出

layout_item_time_select.xml<?xml version="1.0" encoding="utf-8"?>

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="wrap_content"

android:layout_height="100dp"

android:background="@android:color/white">

android:layout_width="wrap_content"

android:layout_height="100dp"

android:orientation="horizontal"

tools:ignore="MissingConstraints">

android:layout_width=".8dp"

android:layout_height="100dp"

android:layout_marginStart=".5dp"

android:layout_marginEnd=".5dp"

android:background="@color/gray_tint" />

android:layout_width="75dp"

android:layout_height="100dp"

android:orientation="vertical">

android:id="@+id/time_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="5dp"

android:singleLine="true"

android:text="8:00 AM"

android:textColor="@android:color/black"

android:textSize="15sp" />

android:id="@+id/time_quarter"

android:layout_width="75dp"

android:layout_height="80dp"

android:layout_gravity="bottom"

android:clickable="true"

android:focusable="true" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值