简体   繁体   English

如何使用图像阵列修复未在回收器视图上显示的图像?

[英]How to fix image not showing on recycler view using image array?

I have created recyclerView on fragment with data on arrays.xml and I have one problem, image not showing in my recyclerView . 我在fragment.xml上的数据片段上创建了recyclerView ,但我arrays.xml一个问题,图像未显示在recyclerView I think its a problem in fragment but I am not sure. 我认为这是一个零散的问题,但我不确定。

This is my distroData.java 这是我的distroData.java

private final String mTitle;
private final String mDescription;
private final String mWeb;
private final int mThumbnail;

public DistroData (String title, String description, String web, int thumbnail){
    mTitle = title;
    mDescription = description;
    mWeb = web;
    mThumbnail = thumbnail;
}

public String getWeb(){
    return mWeb;
}

public int getThumbnail(){
    return mThumbnail;
}

public String getTitle(){
    return mTitle;
}

public String getDescription(){
    return mDescription;
}

} }

and this is my fragment : 这是我的片段:

private void getDatas(){
    mGetDatas = new AsyncTask<Void, Void, Boolean>(){
        List<PerintahLinuxData> datas;
        String[] titles;
        String[] descriptions;
        int[] thumbnails;

        @Override
        public void onPreExecute(){
            super.onPreExecute();
            datas = new ArrayList<>();
            titles = getActivity().getResources().getStringArray(R.array.p_title);
            descriptions = getActivity().getResources().getStringArray(R.array.p_desc);
            thumbnails = getActivity().getResources().getIntArray(R.array.p_thumbnail);
        }

and this is my adapter : 这是我的适配器:

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.title.setText(mDatas.get(position).getTitle());
    holder.description.setText(mDatas.get(position).getDescription());
    holder.thumbnail.setImageResource(mDatas.get(position).getThumbnail());
}

您没有向我们展示适配器更新方法,但我只能猜测您在加载数据后忘记在适配器上使用notifyDataSetChange()方法。

使用此行,因为您将其图像数组放入了缩略图中。

    holder.thumbnail.setImageResource(thumbnails.get(position).getThumbnail());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM