【发布时间】:2021-09-04 17:16:58
【问题描述】:
我只是为我的 recyclerview 制作了一个适配器。像这样:
class CustomerAdapter(mCtx:Context,val customers:ArrayList<Customer>):RecyclerView.Adapter<CustomerAdapter.ViewHolder>(){
我有一个 xml 布局文件来扩充 recycleview 项目。
但问题出在onCreateViewHolder ...我无法访问膨胀的元素...
在我的 onCreateViewHolder 方法中编写的代码:
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomerAdapter.ViewHolder {
val v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lo_customers, parent, false);
var txt = v.id
}
我无法通过 id 访问视图元素。
【问题讨论】:
-
你在kotlin文件中导入了合成布局吗?
-
是的!我忘了加
import kotlinx.android.synthetic.main.lo_customers.view.*,谢谢提醒 -
合成已弃用,考虑迁移到视图绑定
标签: android android-studio kotlin android-recyclerview