0

When the activity initially loaded reqcycler view all items loaded succesfully but on scrolling from up to down some data get lossed and not displayed as items. if i continue to scroll up and down it agian come back. how to fix this problem.

This is my on (bindviewholder) method code.

public void onBindViewHolder(CustomViewholder holder, int position) {
            JSONObject jsonObject=null;

            if(arrayList!=null) {
                  try {

                      jsonObject=new JSONObject(arrayList.get(position));
                      if(!jsonObject.getString("id").equals(id)){
                          holder.textView.setText(jsonObject.getString("username"));
                          Picasso.with(getActivity()).load(jsonObject.getString("profile")).resize(100, 100).into(holder.imageView);


                         // Toast.makeText(getActivity(),"id was equal",Toast.LENGTH_LONG).show();


                      }else {
                          holder.v.setVisibility(View.GONE);
                          holder.v.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
                      }
                  } catch (JSONException e) {

                        e.printStackTrace();
                  }

              }else{
                  holder.textView.setText("no data");
              }


        }
rsd123
  • 55
  • 9
  • Someone already answered this question, see this https://stackoverflow.com/a/29102232/4816020 – ratj Dec 23 '18 at 19:27
  • you have to add holder.setIsRecyclable(false) at the start of this function – ratj Dec 23 '18 at 19:28
  • did you try to disable recycling ? `holder.setIsRecyclable(false);` – Oussema Aroua Dec 23 '18 at 19:28
  • is there any `JSONExeption` in your log cat? – MrX Dec 24 '18 at 01:20
  • No there is not jsonexception.and if do setIsrecyclable(false) then what will be advantaage of using recyclerview – rsd123 Dec 24 '18 at 03:42
  • `onBind` will call many time. `No, it will call o every your scroll. So if you have exception in your bind, the scroll will recreate on your bind. I have been use many-many Recyclerview with JSON as data and `setIsRecyclable(false) with exception in `onBind` is nothing. – MrX Dec 24 '18 at 05:16
  • 1
    Try below link. I got a solution from below link. https://stackoverflow.com/questions/51083708/images-repeated-in-gridview/51084250#51084250 – Hardik Vaghasiya Dec 26 '18 at 11:18
  • It did work succesfully – rsd123 Dec 27 '18 at 04:19

0 Answers0