RecyclerView:没有附加适配器;跳过布局 46545
RecyclerView: No adapter attached; skipping layout 46545
有人知道可行的解决方案吗? None 的其他线程提供了帮助。
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
binding.mainRecyclerView.layoutManager = LinearLayoutManager(this)
binding.mainRecyclerView.setHasFixedSize(true)
adapter = MainRecyclerAdapter(this, null)
binding.mainRecyclerView.adapter = MainRecyclerAdapter(this, null)
}
这样做:
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.mainRecyclerView.layoutManager = LinearLayoutManager(this)
binding.mainRecyclerView.setHasFixedSize(true)
adapter = MainRecyclerAdapter(this, null)
binding.mainRecyclerView.adapter = MainRecyclerAdapter(this, null)
当您使用 View Binding 时,您必须将根视图传递给 setContentView()
有人知道可行的解决方案吗? None 的其他线程提供了帮助。
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
binding.mainRecyclerView.layoutManager = LinearLayoutManager(this)
binding.mainRecyclerView.setHasFixedSize(true)
adapter = MainRecyclerAdapter(this, null)
binding.mainRecyclerView.adapter = MainRecyclerAdapter(this, null)
}
这样做:
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.mainRecyclerView.layoutManager = LinearLayoutManager(this)
binding.mainRecyclerView.setHasFixedSize(true)
adapter = MainRecyclerAdapter(this, null)
binding.mainRecyclerView.adapter = MainRecyclerAdapter(this, null)
当您使用 View Binding 时,您必须将根视图传递给 setContentView()