recyclerview No adapter attached; skipping layout

后端 未结 30 3158
走了就别回头了
走了就别回头了 2020-11-21 04:51

Just implemented RecyclerView in my code, replacing ListView.

Everything works fine. The data is displayed.

But error messages are

30条回答
  •  一生所求
    2020-11-21 05:22

    Adding yet another answer since I came across this thread googling the error. I was trying to initialize a PreferenceFragmentCompat but I forgot to inflate the preference XML in onCreatePreferences like this:

    class SettingsFragment : PreferenceFragmentCompat() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            val inflater = LayoutInflater.from(context)
            inflater.inflate(R.layout.fragment_settings, null)
        }
    
        override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
            // Missing this line here:
            //   setPreferencesFromResource(R.xml.settings, rootKey)
        }
    }
    

    The error was a mystery until I realized that PreferenceFragmentCompat must be using a RecyclerView internally.

提交回复
热议问题