私のアプリはスクロール中にイメージを変えるいくつかのアイテムを見た以外は問題なく、何とかそれはリサイクルの問題だとわかっていますが、解決方法はわかりません。私はそこから考えているので、私のアダプターでいくつかのコードの変更を試みたが、私は成功しなかった。スクロール中にカスタムRecyclerView内のアイテムイメージが変更されるのはなぜですか?
public void onBindViewHolder(CustomAdapter_VersionR.MyViewHolder holder, int position) {
//get current product of the list
currentProduit = productList.get(position);
try {
getImgUrl = currentProduit.getUrlImageList_thumb().get(0);
Picasso.with(context).load(getImgUrl).fit().into(myImageView);
Log.i("INFO", "Image loaded");
} catch (Exception e) {
myImageView.setImageResource(R.drawable.no_image);
Log.e("ERROR", "No image or image error");
e.printStackTrace();
}
ダウンロードイメージについては、私はPicassoを使用しています。ありがとうございました!
EDIT:FULLアダプタ
private Product currentProduit;
private ImageView myImageView;
private Context context;
private List<Product> productList;
private String getAgencyName, getImgUrl;
private List<String> getUrlList_Thumb;
private List<String> getUrlList_Full;
private ImageButton favorite_img_btn;
private boolean star_isClicked;
public CustomAdapter_VersionR(Context ctx, List<Product> products) {
this.context = ctx;
this.productList = products;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private TextView title, descrip, price, agency, country, city, type, nbRoom;
public MyViewHolder(View view) {
super(view);
//references to layout
title = (TextView) view.findViewById(R.id.title_product);
descrip = (TextView) view.findViewById(R.id.descrip_product);
price = (TextView) view.findViewById(R.id.price_product);
myImageView = (ImageView) view.findViewById(R.id.img_product);
agency = (TextView) view.findViewById(R.id.agency_product);
country = (TextView) view.findViewById(R.id.country_product);
city = (TextView) view.findViewById(R.id.city_product);
type = (TextView) view.findViewById(R.id.type_product);
nbRoom = (TextView) view.findViewById(R.id.nbRoom_product);
}
}
@Override
public CustomAdapter_VersionR.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_list_row, parent, false);
Log.i("INFO", "Creation ok");
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(CustomAdapter_VersionR.MyViewHolder holder, int position) {
//get current product of the list
currentProduit = productList.get(position);
try {
getImgUrl = currentProduit.getUrlImageList_thumb().get(0);
Picasso.with(context).load(getImgUrl).fit().into(myImageView);
Log.i("INFO", "Image loaded");
} catch (Exception e) {
myImageView.setImageResource(R.drawable.no_image);
Log.e("ERROR", "No image or image error");
e.printStackTrace();
}
holder.agency.setText(currentProduit.getNomAgence();
holder.descrip.setText(currentProduit.getDescription());
holder.title.setText(currentProduit.getTitre());
holder.price.setText(currentProduit.getPrix());
holder.nbRoom.setText(currentProduit.getNbPieces());
holder.country.setText(currentProduit.getPays());
holder.city.setText(currentProduit.getVille());
holder.type.setText(currentProduit.getType_produit());
}
@Override
public int getItemCount() {
return productList.size();
}
編集:いくつかの研究の後、そこに追加する私のonBindViewHolderで何かがだが、プレースホルダが動作しない、私はそれと間違っsoemthingをやっているかもしれません。..
アダプターの完全なコードを入力してください。 ViewHolderを使用していないようです。 – drulabs
@drulabs、完全なコードを投稿しました:) – Jay