配置Wifi

This commit is contained in:
2026-04-30 13:48:46 +08:00
parent e8cb357446
commit 2038b6f7a4
4 changed files with 99 additions and 0 deletions

View File

@@ -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
}