当前位置: 首页 > 知识库问答 >
问题:

RecyclerView:未附加适配器;跳过布局

长孙翔
2023-03-14

我一直在stackoverflow和这篇博文上阅读不同的答案,并试图实现它们的解决方案,但我仍然得到错误:

public class ProfileFragment extends Fragment {

private ModelUser user;

private View view;
private RecyclerView gridView;
private ProfilePhotoRecyclerViewAdapter adapter;
private List<ModelAttachment> photoList = new ArrayList<ModelAttachment>();

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_profile, container, false);

    initializeRecyclerView();

    //Get extra info for user
    QueryAPI query = new QueryAPI();
    query.userExtra(user, new QueryAPI.ApiResponse<ModelUser>() {
        @Override
        public void onCompletion(ModelUser result) {
            user = result;
                photoList.clear();
                photoList.addAll(0,user.getPhotos());

                adapter.notifyDataSetChanged();

            }
        });

     return view;

}

}
void initializeRecyclerView() {
        gridView = (RecyclerView) view.findViewById(R.id.grid_view);
        StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.HORIZONTAL );
        adapter = new ProfilePhotoRecyclerViewAdapter(getActivity(), photoList);
        gridView.setAdapter(adapter);
        gridView.setLayoutManager(gridLayoutManager);
        gridView.setHasFixedSize(true);
    }

片段中的布局:

 <android.support.v7.widget.RecyclerView
  android:id="@+id/grid_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

和项目的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageView"
    android:contentDescription="@string/image_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:adjustViewBounds="true" />

 </LinearLayout>

我做错了什么?

编辑:以下是适配器:

public class ProfilePhotoRecyclerViewAdapter extends  RecyclerView.Adapter<ProfilePhotoRecyclerViewAdapter.ViewHolder> {

    private LayoutInflater inflater;
    private List<ModelAttachment> photos; //data
    private Activity listContext;
    private int listRowLayoutId;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();


    public ProfilePhotoRecyclerViewAdapter(Activity context, List<ModelAttachment> objs) {
        photos = objs;
        listContext = context;
        this.notifyDataSetChanged();
    }

    @Override
    public ProfilePhotoRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {

        View itemView = LayoutInflater.from(listContext).inflate(R.layout.profile_photogrid_item, parent, false);

        return new ProfilePhotoRecyclerViewAdapter.ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ProfilePhotoRecyclerViewAdapter.ViewHolder viewHolder, int i) {

        ModelAttachment photo = photos.get(i);
        viewHolder.imageView.setImageUrl(photo.getUrl(), imageLoader);
    }

    @Override
    public int getItemCount() {
        return photos.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        ModelAttachment photo;
        public NetworkImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            this.imageView = (NetworkImageView) itemView.findViewById(R.id.imageView);
        }
    }
}

暂时还没有答案

 类似资料:
  • 我正在使用一个片段来查看一个RecyclerView。但我总是犯这个错误 E/RecyclerView:未附加适配器;跳过布局 我已经为我的recyclerview创建了一个适配器,但布局没有显示。php后端运行良好。谁能帮帮我。下面是我的片段和适配器代码 Tips.java TipAdapter.java

  • 我已经提到了相当少的帖子关于这个错误,但没有一个能够解决我的问题。我有一个片断,在这里我使用修改获得了我的值,我已经在下面显示了: 下面是我的RecyclerView适配器类:

  • 我收到以下错误:“RecyclerView:未附加适配器;跳过布局”但我已附加适配器...我试过很多不同的方法,但都解决不了这个错误。 我正在使用Volley库获取数据。当我启动activity时,直到结束只有进度条可见,并且收到上面的Logcat消息。我已经在中添加了带有适配器的。你能帮帮我吗? 下面是我的代码: 主要活动 地震适配器 mainactivity.xml EquestakerAw.

  • 我需要帮助,我有一个错误,那就是这个:E/recyclerView:没有连接适配器;跳过布局 代码: 公共视图onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){View View=inflater.inflate(r.layout.fragment_chats,container,

  • 我有一个回收演示,但当我运行该演示时,总是显示错误消息“recycleview recycerview:No adapter attached;skipping layout” 这是我主要的activity课 这是我的RecyclerViewAdapter代码

  • 我的应用程序正在正确地从parse.com获取信息,但没有像以前那样在recyclerview中正确地显示信息。系统提示我错误消息“no adapter attached;skipping layout”,并且recyclerview仍然为空。请你检查一下我的程序并通知我任何我可能错过的错误好吗? $ $