Android 适配器数据会交替更改
这种情况是适配器结果不断交替变化 i、 e 首先是: [, 然后: [ 对于相同的网络呼叫 这是我的适配器类:Android 适配器数据会交替更改,android,Android,这种情况是适配器结果不断交替变化 i、 e 首先是: [, 然后: [ 对于相同的网络呼叫 这是我的适配器类: public ImageCustomAdapter(ArrayList<ModelGettyImages> images,Context context) { this.images = images; this.context = context; } @Override public ImagesViewHolder onCreateViewHold
public ImageCustomAdapter(ArrayList<ModelGettyImages> images,Context context) {
this.images = images;
this.context = context;
}
@Override
public ImagesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_row, parent, false);
ImagesViewHolder imagesViewHolder = new ImagesViewHolder(view);
return imagesViewHolder;
}
@Override
public void onBindViewHolder(ImagesViewHolder holder, int position) {
List<String> text = images.get(position).getTitle();
Log.d("TitleAdapter : ",images.get(position).getTitle().toString());
List<String> image = images.get(position).getImagePath();
Log.d("ImageAdapter : ", images.get(position).getImagePath().toString());
holder.title.setText(text.get(position));
Picasso.with(context).load(image.get(position)).fit().centerCrop().into(holder.image);
}
@Override
public int getItemCount() {
return images.size();
}
public class ImagesViewHolder extends RecyclerView.ViewHolder{
ImageView image;
TextView title;
public ImagesViewHolder(View itemView) {
super(itemView);
image = (ImageView)itemView.findViewById(R.id.imageView);
title = (TextView)itemView.findViewById(R.id.textView);
}
}
公共ImageCustomAdapter(ArrayList图像,上下文){
这个。图像=图像;
this.context=上下文;
}
@凌驾
公共图像ViewHolder onCreateViewHolder(视图组父级,int-viewType){
View=LayoutFlater.from(parent.getContext()).flate(R.layout.card_行,parent,false);
ImagesViewHolder ImagesViewHolder=新的ImagesViewHolder(视图);
返回图像查看文件夹;
}
@凌驾
BindViewHolder上的公共void(图像文件夹持有人,内部位置){
List text=images.get(position.getTitle();
Log.d(“TitleAdapter:”,images.get(position.getTitle().toString());
List image=images.get(position.getImagePath();
Log.d(“ImageAdapter:”,images.get(position.getImagePath().toString());
holder.title.setText(text.get(position));
毕加索.with(context).load(image.get(position)).fit().centerCrop()装入(holder.image);
}
@凌驾
public int getItemCount(){
返回图像。size();
}
公共类ImagesViewHolder扩展了RecyclerView.ViewHolder{
图像视图图像;
文本视图标题;
公共图像查看文件夹(查看项目视图){
超级(项目视图);
image=(ImageView)itemView.findViewById(R.id.ImageView);
title=(TextView)itemView.findViewById(R.id.TextView);
}
}
有趣的是,标题字段是相同的
回应类别:
private ModelGettyImages getImageDetails(String jsonData) throws JSONException {
boolean ascending = sharedPreferences.getBoolean("Ascending",false);
Log.d("Ascending",Boolean.toString(ascending));
boolean descending = sharedPreferences.getBoolean("Descending",false);
Log.d("descending",Boolean.toString(descending));
String pathURI = "";
JSONObject imageData = new JSONObject(jsonData);
int resultCount = imageData.optInt("result_count");
Log.d("Result Count: ", Integer.toString(resultCount));
JSONArray imageArray = imageData.optJSONArray("images");
for (int i = 0; i < imageArray.length(); i++)
{
JSONObject img = imageArray.optJSONObject(i);
allID.add(i,img.optString("id"));
allTitles.add(i,img.optString("title"));
Log.d("Image ID: ", allID.get(i));
Log.d("Image Title: ", allTitles.get(i));
JSONArray imagePath = img.optJSONArray("display_sizes");
for (int j = 0; j < imagePath.length(); j++)
{
JSONObject jb = imagePath.optJSONObject(j);
allImagePath.add(j,jb.getString("uri"));
Log.d("Image Path: ", allImagePath.get(j));
}
if( ascending )
{
Log.d("Ass","True");
Collections.sort(allTitles, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
}
else if( descending )
{
Log.d("Des","True");
Collections.sort(allTitles, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s2.compareToIgnoreCase(s1);
}
});
}
Log.d("Image Title Sort: ", allTitles.get(i));
modelGettyImages.setID(allID);
modelGettyImages.setTitle(allTitles);
modelGettyImages.setImagePath(allImagePath);
ImagesList.add(modelGettyImages);
}
return modelGettyImages;
}
private ModelGettyImages getImageDetails(字符串jsonData)抛出JSONException{
布尔升序=SharedReferences.getBoolean(“升序”,false);
Log.d(“升序”,Boolean.toString(升序));
boolean descending=SharedReferences.getBoolean(“descending”,false);
Log.d(“降序”,Boolean.toString(降序));
字符串pathURI=“”;
JSONObject imageData=新的JSONObject(jsonData);
int resultCount=imageData.optInt(“结果计数”);
Log.d(“结果计数:”,Integer.toString(resultCount));
JSONArray imageArray=imageData.optJSONArray(“图像”);
对于(int i=0;i
在加载url之前,请尝试重置imageview。请使用此代码
Picasso.with(this.context).cancelRequest(holder.image);
以前
Picasso.with(context).load(image.get(position)).fit().centerCrop().into(holder.image);
不,问题不在于毕加索,而在于List image=images.get(position).getImagePath();保持变化图像的结果是相反的,即最后一幅图像在我的列表中是第一幅,你能发布你的json吗?我的响应类中的第一个json元素:我的适配器类中的第一个元素:[