android - 我想问为什么将空适配器设置为回收站 View 很重要?有什么优势吗?有什么缺点吗?

标签 android android-recyclerview

我有一个回收器 View ,它正在从服务器获取数据并且工作正常。 但是我收到一个错误“没有连接适配器;跳过布局”,我知道我可以通过设置一个空适配器来解决这个问题。但这很重要吗?它也可以在没有空适配器的情况下工作。

编辑:-

我知道如何解决这个问题。我问它是否在不设置空适配器的情况下工作。 为什么设置空适配器很重要?

我的方法是设置回收器 View 。

private void setUpCategoryRecyclerView(List<Category> allCategories) {

    final RecyclerView categoryListRecyclerView = (RecyclerView) getViewById(R.id.recyclerView);
    final CategoryAdapter categoryAdapter = new CategoryAdapter(allCategories, false);

    categoryAdapter.setOnItemClickListener(new CategoryAdapter.clickListener() {

        @Override
        public void onItemClick(int position, View v) {

            final TextView CategoryName = v.findViewById(R.id.categoryName);
            final Bundle bundle = new Bundle();  // Payload for next fragment
            bundle.putString(CATEGORY, CategoryName.getText().toString());
            FragmentsCallBack.CallBack(bundle);
        }
    });
    categoryListRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    categoryListRecyclerView.setAdapter(categoryAdapter);
    enableSearch(allCategories, categoryAdapter);
}

最佳答案

因为它是一个警告,您可以忽略它,但 SDK 的开发人员抛出此警告,这意味着您应该处理它。虽然它不会损害或崩溃您的应用程序,但建议您摆脱它,因为干净的 logcat 可以帮助您更快、更高效地进行调试。

如果您最初没有数据,只需先设置一个适配器,一旦有数据就更新它。

关于android - 我想问为什么将空适配器设置为回收站 View 很重要?有什么优势吗?有什么缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54865878/

相关文章:

android - java.lang.RuntimeException : Unable to start activity ComponentInfo {. 。}

android - RecyclerView 不会显示任何数据

java - 在不使用任何第三方的情况下将 map 数据映射到同一卡片 View 中的 Recyclerview Adapter

android - Recyclerview 网络的 ImageView 中的相同图像

Java ArrayList<String> 如何按索引排序/排序?

android.support.test.espresso.NoActivityResumedException : No activities in stage RESUMED

android - 来自 Google Cloud Messaging 的消息到达设备需要多长时间

java - Android NativeActivity : AttachCurrentThread JNIInvokeInterface is not a structure or union

android - 如何在 RecyclerView Adapter 中使用 TextWatcher

javascript - Canvas 不显示在移动设备上