刷新整个RecyclerView

时间:2017-05-24 06:18:27

标签: android android-recyclerview recycler-adapter recyclerview-layout

如何更新整个RecyclerView。我尝试了notifyDataSetChanged()但它只更新了可见位置。但我想更新enitre RecyclerView。

我试过了adapter.notifyItemRangeChanged(0,adapter.getItemCount());但这个也没有刷新整个RecyclerView。

我需要RecyclerView位置从0到总计数从刷新数据开始,因为基于位置数据正在提取。

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

    ArrayList<Model_Pager> arrayList;

    Activity activity;

    static ViewHolder viewHolder;

    SettingApiSave cust_setting;

    @Override
    public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);

        Log.v("HLVCategoryAdapter","position:"+position);
    }

    public HLVAdapter(Activity activity, ArrayList<Model_Pager> arrayList) {
        super();
        this.activity = activity;
        this.arrayList = arrayList;


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.category_list_item, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(v);

        return viewHolder;
    }

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

        HLVAdapter.viewHolder = viewHolder;

        Log.e("car_nameeeeee", "i:  " + save_add.getString("name" + i, ""));



    }

    @Override
    public int getItemCount() {
        return UberMapFragment.Total_Category;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {


        public RelativeLayout lay_rel_img;

        public ViewHolder(View itemView) {
            super(itemView);
            lay_rel_img = (RelativeLayout) itemView.findViewById(R.id.lay_rel_img);



        }


    }


}

这是我宣布的recyclview。

   mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    mRecyclerView.setHasFixedSize(true);

    mLayoutManager = new LinearLayoutManager(getActivity(), 
    LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView.setLayoutManager(mLayoutManager);

我用mAdapter.notifyDataSetChanged()

更新recycleview

请任何人建议我解决。谢谢

recyclewview

2 个答案:

答案 0 :(得分:0)

基本上,它是不可能的,因为回收者视图没有它在滚动上绑定的整个数据所以你不能用notifyItemRangeChanged(0,adapter.getItemCount())刷新整个回收的视图;或者任何此通知属性。循环视图仅包含视图中可用的数据。

答案 1 :(得分:0)

唯一的解决方案是重新创建您的recycleView。 但为什么你需要更新项目没有显示?