配置Wifi
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.example.defenseapplication.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.databinding.ItemWifiBinding
|
||||
|
||||
class WifiListAdapter(
|
||||
private val wifiList: List<String>,
|
||||
private val onItemClick: (String) -> Unit
|
||||
) : RecyclerView.Adapter<WifiListAdapter.ViewHolder>() {
|
||||
|
||||
inner class ViewHolder(val binding: ItemWifiBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
itemView.setOnClickListener {
|
||||
val position = adapterPosition
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
onItemClick(wifiList[position])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(wifiName: String) {
|
||||
binding.tvWifiName.text = wifiName
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = ItemWifiBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(wifiList[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = wifiList.size
|
||||
}
|
||||
Reference in New Issue
Block a user