标签云

微信群

扫码加入我们

WeChat QR Code

I have tried multiple answers, also set the cache size to therecyclerView, but no success. layoutManager = new LinearLayoutManager(getActivity());recyclerView.setLayoutManager(layoutManager);recyclerView.setHasFixedSize(true);recyclerView.setItemViewCacheSize(25);recyclerView.setDrawingCacheEnabled(true);recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);// here is data from the REstAPi by using Rtrofit WIth Rx java,public void onNext(HomeDS homeDS) {progressBar.invalidate();progressBar.setVisibility(View.GONE);swipeContainer.setRefreshing(false);streamdata.addAll(homeDS.getStream());Setting adapter after callng the api method:callRestfulApi();setAdapter();Adapter method: recyclerViewHomeAdapter = new RecyclerViewHomeAdapter(streamdata,getActivity());recyclerView.setAdapter(recyclerViewHomeAdapter);Now this is my adapter: calling the item view type, and actually 8 type of layouts i have,@Overridepublic int getItemViewType(int position) {if (dataList.get(position).getSectionID() == 59)return layout0;else if (dataList.get(position).getSectionID() == 17)return layout1;else if (dataList.get(position).getSectionID() == 5)return layout2;else if (dataList.get(position).getSectionID() == 119)return layout3; else if (dataList.get(position).getSectionID() == 122)if (dataList.get(position).getType().equals("48")) {return layout7;} else {return layout9;}return layout9; @NonNull@Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view;fontUniversal = new FontUniversal(context);RecyclerView.ViewHolder viewHolder = null;if (viewType == layout0) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_view, parent, false);viewHolder = new Viewholder(view);} else if (viewType == layout1) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.collage_review, parent, false);viewHolder = new Viewholderone(view);} else if (viewType == layout2) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_layout, parent, false);viewHolder = new ViewholderTwo(view);} else if (viewType == layout3) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dashboard_notification, parent, false);viewHolder = new ViewholderThree(view);} else if (viewType == layout4) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_reply, parent, false);viewHolder = new ViewholderFour(view);} else if (viewType == layout5) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.vedio_view, parent, false);viewHolder = new ViewholderFive(view);} else if (viewType == layout6) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pic_layout, parent, false);viewHolder = new ViewholderSix(view);} else if (viewType == layout7) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.mcqs_view, parent, false);viewHolder = new ViewholderSeven(view);} else if (viewType == layout9) {view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pool_view, parent, false);viewHolder = new ViewholderNine(view);}Here in layout I check which layout to inflate in the recyclerView, I made the 8 types of ViewHolders according to the layout.@Overridepublic void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder,final int position) {if (holder.getItemViewType() == layout0) {Viewholder viewholder = (Viewholder) holder;Setting the data in the fields: final String[] name_loc = dataList.get(position).getMemberName().split(":");if (dataList.get(position).getMemberImage() != null) {String img = dataList.get(position).getMemberImage();img = img.replaceAll(" ", "%20");if (!img.equals("https://ikddata.ilmkidunya.com/images/no_img.jpg")) { Glide.with(context).load(img).into(viewholder.img_user_main);}}String name = name_loc[0];if (!name.isEmpty()) {viewholder.tv_username.setText(name);}if (name_loc.length > 1) {viewholder.tv_location.setText(name_loc[1]);} else {viewholder.tv_location.setText("Guest");}if (dataList.get(position).getUrl().equals("http://www.ilmkidunya.com/ba/")) {viewholder.tv_refrence.setVisibility(View.GONE);} else {viewholder.tv_refrence.setText(dataList.get(position).getTitle());viewholder.tv_refrence.setTypeface(fontUniversal.tcm);}viewholder.tv_time.setText(dataList.get(position).getDateFormats());viewholder.tv_comment.setText(dataList.get(position).getDescription());if (!dataList.get(position).getCommentType().equals("1")) {if (dataList.get(position).getCommentType().equals("2")) {String image = "" + dataList.get(position).getThumbImage();image = image.replaceAll(" ", "%20");Glide.with(context).load(image).into(viewholder.img_comment);viewholder.img_relativelayout.setVisibility(View.VISIBLE);} else if (dataList.get(position).getCommentType().equals("5")) {String[] msg = dataList.get(position).getAttachment().split("/");int msgLenght = msg.length;msgLenght--;viewholder.file_layout.setVisibility(View.VISIBLE);viewholder.filename.setText("" + msg[msgLenght]);viewholder.btn_download.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {new DownloadFile(context).execute(dataList.get(position).getAttachment());}}); else if (holder.getItemViewType() == layout1) {Viewholderone viewholderone = (Viewholderone) holder;viewholderone.tv_universsity.setText(dataList.get(position).getCollegeName()); viewholderone.tv_time.setText(dataList.get(position) .getDatedStr()); viewholderone.tv_username.setText(dataList. get(position).getMemberName());String img1 = dataList.get(position).getMemberImage();viewholderone.pg_rating. setProgress(Math.round(dataList.get(position).getRating()));viewholderone.pg_rating.setMax(5);img1 = img1.replaceAll(" ", "%20");if (img1.equals("https://ikddata.ilmkidunya.com/images/no_img.jpg")) {viewholderone.img_user.setImageResource(R.drawable.ic_user);} else {Glide.with(context).load(img1).into(viewholderone.img_user);}// call for the collage details} else if (holder.getItemViewType() == layout2){....}