Why in specific range same image is duplicating in recyclerview?












0















I'm trying to develop android application which can load images from the url in to RecyclerView With the help of Picasso library. But the problem comes that after some sequence "in my case after every 6 image" same image is duplicating in recyclerview. I'm added some code



@Override
public int getItemCount() {
return data.length;
}

@Override
public long getItemId(int position) {
return position;
}


in my adapter but this is not working for me.
Below is my currant adapter code please help me to findout the solution for this.



public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
private Context context;
private Img data;

public MyAdapter(Context context, Img data) {
this.context = context;
this.data = data;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.image_row, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
final Img user = data[position];

final String imageStr = user.getImgurl();
String taKey = loadTaluka();
final String id = user.getImgId().toString();

if (user.getTaluka().equals(taKey)) {
float date = Float.parseFloat(user.getDateTime());
float lastDayDate = Float.parseFloat(dispDate()) - 1;
if (date >= lastDayDate) {
Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).networkPolicy(NetworkPolicy.OFFLINE).into(holder.myImg, new Callback() {
@Override
public void onSuccess() {
}

@Override
public void onError() {
Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).into(holder.myImg);
}
});



}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, LoadImg.class);
intent.putExtra("url", imageStr);
intent.putExtra("id", id);
context.startActivity(intent);
}
});

}

}

@Override
public int getItemCount() {
return data.length;
}

@Override
public long getItemId(int position) {
return position;
}


/*
@Override
public int getItemViewType(int position) {
return position;
}*/
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView userTitle;
TextView age;
TextView country;
TextView url;
public ImageView myImg;

public MyViewHolder(View itemView) {
super(itemView);
myImg = (ImageView) itemView.findViewById(R.id.postImg);
}
}


//Extras


private String loadTaluka() {
SharedPreferences sf = context.getSharedPreferences("Taluka", MODE_PRIVATE);
return sf.getString("taluka", "a");
}

//Image Viewholder Adapter End
private String dispDate() {
Date c = Calendar.getInstance().getTime();

@SuppressLint("SimpleDateFormat") SimpleDateFormat day = new SimpleDateFormat("dd");
String dayFinal = day.format(c);

@SuppressLint("SimpleDateFormat") SimpleDateFormat month = new SimpleDateFormat("MM");
String monthFinal = month.format(c);

@SuppressLint("SimpleDateFormat") SimpleDateFormat year = new SimpleDateFormat("yyyy");
String yearFinal = year.format(c);

@SuppressLint("SimpleDateFormat") SimpleDateFormat hour = new SimpleDateFormat("HH");
String hourFinal = hour.format(c);

String finalDate = Integer.toString(Integer.parseInt(dayFinal) + Integer.parseInt(monthFinal) + Integer.parseInt(yearFinal)) + "." + hourFinal;

return finalDate;
}


}

-Thankyou.









share|improve this question



























    0















    I'm trying to develop android application which can load images from the url in to RecyclerView With the help of Picasso library. But the problem comes that after some sequence "in my case after every 6 image" same image is duplicating in recyclerview. I'm added some code



    @Override
    public int getItemCount() {
    return data.length;
    }

    @Override
    public long getItemId(int position) {
    return position;
    }


    in my adapter but this is not working for me.
    Below is my currant adapter code please help me to findout the solution for this.



    public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private Context context;
    private Img data;

    public MyAdapter(Context context, Img data) {
    this.context = context;
    this.data = data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View view = inflater.inflate(R.layout.image_row, parent, false);
    MyViewHolder holder = new MyViewHolder(view);
    return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
    final Img user = data[position];

    final String imageStr = user.getImgurl();
    String taKey = loadTaluka();
    final String id = user.getImgId().toString();

    if (user.getTaluka().equals(taKey)) {
    float date = Float.parseFloat(user.getDateTime());
    float lastDayDate = Float.parseFloat(dispDate()) - 1;
    if (date >= lastDayDate) {
    Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).networkPolicy(NetworkPolicy.OFFLINE).into(holder.myImg, new Callback() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError() {
    Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).into(holder.myImg);
    }
    });



    }
    holder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Intent intent = new Intent(context, LoadImg.class);
    intent.putExtra("url", imageStr);
    intent.putExtra("id", id);
    context.startActivity(intent);
    }
    });

    }

    }

    @Override
    public int getItemCount() {
    return data.length;
    }

    @Override
    public long getItemId(int position) {
    return position;
    }


    /*
    @Override
    public int getItemViewType(int position) {
    return position;
    }*/
    public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView userTitle;
    TextView age;
    TextView country;
    TextView url;
    public ImageView myImg;

    public MyViewHolder(View itemView) {
    super(itemView);
    myImg = (ImageView) itemView.findViewById(R.id.postImg);
    }
    }


    //Extras


    private String loadTaluka() {
    SharedPreferences sf = context.getSharedPreferences("Taluka", MODE_PRIVATE);
    return sf.getString("taluka", "a");
    }

    //Image Viewholder Adapter End
    private String dispDate() {
    Date c = Calendar.getInstance().getTime();

    @SuppressLint("SimpleDateFormat") SimpleDateFormat day = new SimpleDateFormat("dd");
    String dayFinal = day.format(c);

    @SuppressLint("SimpleDateFormat") SimpleDateFormat month = new SimpleDateFormat("MM");
    String monthFinal = month.format(c);

    @SuppressLint("SimpleDateFormat") SimpleDateFormat year = new SimpleDateFormat("yyyy");
    String yearFinal = year.format(c);

    @SuppressLint("SimpleDateFormat") SimpleDateFormat hour = new SimpleDateFormat("HH");
    String hourFinal = hour.format(c);

    String finalDate = Integer.toString(Integer.parseInt(dayFinal) + Integer.parseInt(monthFinal) + Integer.parseInt(yearFinal)) + "." + hourFinal;

    return finalDate;
    }


    }

    -Thankyou.









    share|improve this question

























      0












      0








      0








      I'm trying to develop android application which can load images from the url in to RecyclerView With the help of Picasso library. But the problem comes that after some sequence "in my case after every 6 image" same image is duplicating in recyclerview. I'm added some code



      @Override
      public int getItemCount() {
      return data.length;
      }

      @Override
      public long getItemId(int position) {
      return position;
      }


      in my adapter but this is not working for me.
      Below is my currant adapter code please help me to findout the solution for this.



      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
      private Context context;
      private Img data;

      public MyAdapter(Context context, Img data) {
      this.context = context;
      this.data = data;
      }

      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      View view = inflater.inflate(R.layout.image_row, parent, false);
      MyViewHolder holder = new MyViewHolder(view);
      return holder;
      }

      @Override
      public void onBindViewHolder(final MyViewHolder holder, int position) {
      final Img user = data[position];

      final String imageStr = user.getImgurl();
      String taKey = loadTaluka();
      final String id = user.getImgId().toString();

      if (user.getTaluka().equals(taKey)) {
      float date = Float.parseFloat(user.getDateTime());
      float lastDayDate = Float.parseFloat(dispDate()) - 1;
      if (date >= lastDayDate) {
      Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).networkPolicy(NetworkPolicy.OFFLINE).into(holder.myImg, new Callback() {
      @Override
      public void onSuccess() {
      }

      @Override
      public void onError() {
      Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).into(holder.myImg);
      }
      });



      }
      holder.itemView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      Intent intent = new Intent(context, LoadImg.class);
      intent.putExtra("url", imageStr);
      intent.putExtra("id", id);
      context.startActivity(intent);
      }
      });

      }

      }

      @Override
      public int getItemCount() {
      return data.length;
      }

      @Override
      public long getItemId(int position) {
      return position;
      }


      /*
      @Override
      public int getItemViewType(int position) {
      return position;
      }*/
      public class MyViewHolder extends RecyclerView.ViewHolder {
      TextView userTitle;
      TextView age;
      TextView country;
      TextView url;
      public ImageView myImg;

      public MyViewHolder(View itemView) {
      super(itemView);
      myImg = (ImageView) itemView.findViewById(R.id.postImg);
      }
      }


      //Extras


      private String loadTaluka() {
      SharedPreferences sf = context.getSharedPreferences("Taluka", MODE_PRIVATE);
      return sf.getString("taluka", "a");
      }

      //Image Viewholder Adapter End
      private String dispDate() {
      Date c = Calendar.getInstance().getTime();

      @SuppressLint("SimpleDateFormat") SimpleDateFormat day = new SimpleDateFormat("dd");
      String dayFinal = day.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat month = new SimpleDateFormat("MM");
      String monthFinal = month.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat year = new SimpleDateFormat("yyyy");
      String yearFinal = year.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat hour = new SimpleDateFormat("HH");
      String hourFinal = hour.format(c);

      String finalDate = Integer.toString(Integer.parseInt(dayFinal) + Integer.parseInt(monthFinal) + Integer.parseInt(yearFinal)) + "." + hourFinal;

      return finalDate;
      }


      }

      -Thankyou.









      share|improve this question














      I'm trying to develop android application which can load images from the url in to RecyclerView With the help of Picasso library. But the problem comes that after some sequence "in my case after every 6 image" same image is duplicating in recyclerview. I'm added some code



      @Override
      public int getItemCount() {
      return data.length;
      }

      @Override
      public long getItemId(int position) {
      return position;
      }


      in my adapter but this is not working for me.
      Below is my currant adapter code please help me to findout the solution for this.



      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
      private Context context;
      private Img data;

      public MyAdapter(Context context, Img data) {
      this.context = context;
      this.data = data;
      }

      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      View view = inflater.inflate(R.layout.image_row, parent, false);
      MyViewHolder holder = new MyViewHolder(view);
      return holder;
      }

      @Override
      public void onBindViewHolder(final MyViewHolder holder, int position) {
      final Img user = data[position];

      final String imageStr = user.getImgurl();
      String taKey = loadTaluka();
      final String id = user.getImgId().toString();

      if (user.getTaluka().equals(taKey)) {
      float date = Float.parseFloat(user.getDateTime());
      float lastDayDate = Float.parseFloat(dispDate()) - 1;
      if (date >= lastDayDate) {
      Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).networkPolicy(NetworkPolicy.OFFLINE).into(holder.myImg, new Callback() {
      @Override
      public void onSuccess() {
      }

      @Override
      public void onError() {
      Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).into(holder.myImg);
      }
      });



      }
      holder.itemView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      Intent intent = new Intent(context, LoadImg.class);
      intent.putExtra("url", imageStr);
      intent.putExtra("id", id);
      context.startActivity(intent);
      }
      });

      }

      }

      @Override
      public int getItemCount() {
      return data.length;
      }

      @Override
      public long getItemId(int position) {
      return position;
      }


      /*
      @Override
      public int getItemViewType(int position) {
      return position;
      }*/
      public class MyViewHolder extends RecyclerView.ViewHolder {
      TextView userTitle;
      TextView age;
      TextView country;
      TextView url;
      public ImageView myImg;

      public MyViewHolder(View itemView) {
      super(itemView);
      myImg = (ImageView) itemView.findViewById(R.id.postImg);
      }
      }


      //Extras


      private String loadTaluka() {
      SharedPreferences sf = context.getSharedPreferences("Taluka", MODE_PRIVATE);
      return sf.getString("taluka", "a");
      }

      //Image Viewholder Adapter End
      private String dispDate() {
      Date c = Calendar.getInstance().getTime();

      @SuppressLint("SimpleDateFormat") SimpleDateFormat day = new SimpleDateFormat("dd");
      String dayFinal = day.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat month = new SimpleDateFormat("MM");
      String monthFinal = month.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat year = new SimpleDateFormat("yyyy");
      String yearFinal = year.format(c);

      @SuppressLint("SimpleDateFormat") SimpleDateFormat hour = new SimpleDateFormat("HH");
      String hourFinal = hour.format(c);

      String finalDate = Integer.toString(Integer.parseInt(dayFinal) + Integer.parseInt(monthFinal) + Integer.parseInt(yearFinal)) + "." + hourFinal;

      return finalDate;
      }


      }

      -Thankyou.






      android android-recyclerview picasso recyclerview-layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 12:26









      Mr. Jay PatelMr. Jay Patel

      143




      143
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Because of Recycler views RAM Management, the recycler view try to load cards from the cache and because of your recycler view's cache, the items loads incorrectly.
          for preventing this you must add an else to your if like this:



          if (date >= lastDayDate)
          {
          //Do Your Code
          }
          else
          {
          //The Default Item View Settings Here...
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458131%2fwhy-in-specific-range-same-image-is-duplicating-in-recyclerview%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Because of Recycler views RAM Management, the recycler view try to load cards from the cache and because of your recycler view's cache, the items loads incorrectly.
            for preventing this you must add an else to your if like this:



            if (date >= lastDayDate)
            {
            //Do Your Code
            }
            else
            {
            //The Default Item View Settings Here...
            }





            share|improve this answer




























              0














              Because of Recycler views RAM Management, the recycler view try to load cards from the cache and because of your recycler view's cache, the items loads incorrectly.
              for preventing this you must add an else to your if like this:



              if (date >= lastDayDate)
              {
              //Do Your Code
              }
              else
              {
              //The Default Item View Settings Here...
              }





              share|improve this answer


























                0












                0








                0







                Because of Recycler views RAM Management, the recycler view try to load cards from the cache and because of your recycler view's cache, the items loads incorrectly.
                for preventing this you must add an else to your if like this:



                if (date >= lastDayDate)
                {
                //Do Your Code
                }
                else
                {
                //The Default Item View Settings Here...
                }





                share|improve this answer













                Because of Recycler views RAM Management, the recycler view try to load cards from the cache and because of your recycler view's cache, the items loads incorrectly.
                for preventing this you must add an else to your if like this:



                if (date >= lastDayDate)
                {
                //Do Your Code
                }
                else
                {
                //The Default Item View Settings Here...
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 12:38









                Mahdi AstaneiMahdi Astanei

                1,5541023




                1,5541023
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458131%2fwhy-in-specific-range-same-image-is-duplicating-in-recyclerview%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin