Android RecyclerView 显示数据甚至不存在
Android RecyclerView show data even not exists
我有一个包含 30 行数据的 RecyclerView。有些行有我得到的图像并用毕加索展示它。
问题是,图像框每 8 行重复一次,即使该行没有图像。
我检查如果图像是空的不显示它,但显示它。
JobAdapter.java
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final MyHolder myHolder = (MyHolder) holder;
JobClass current=data.get(position);
myHolder.name.setText(current.title);
myHolder.manager.setText(current.manager);
String phone= (String) new KerashDao(context).JobinfoGetValue(current.job_id.toString(),new KerashDao(context).SettingGetValue("phone").toString());
myHolder.phonecall.setText(phone.toString());
try {
if(!current.image.isEmpty()) {
Picasso.with(context)
.load(current.image)
.placeholder(R.drawable.icn_loading)
.into(myHolder.picture, new Callback() {
@Override
public void onSuccess() {myHolder.picture.setVisibility(View.VISIBLE);}
@Override
public void onError() {
myHolder.picture.setVisibility(View.GONE);
}
});
}
}catch (Exception ex){Log.i("JobAdapter2",ex.getMessage().toString()+"");}
}
RecyclerView
回收代表每一行的视图。这意味着给定的视图一旦滚出屏幕,就会被另一行重新使用。由于您在某个时候将图像加载到该视图中,它会一直存在直到您清除它。
在您的 if(!current.image.isEmpty())
语句中添加一个 else
子句,以清除 ImageView
中的图像。
我有一个包含 30 行数据的 RecyclerView。有些行有我得到的图像并用毕加索展示它。 问题是,图像框每 8 行重复一次,即使该行没有图像。 我检查如果图像是空的不显示它,但显示它。
JobAdapter.java
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final MyHolder myHolder = (MyHolder) holder;
JobClass current=data.get(position);
myHolder.name.setText(current.title);
myHolder.manager.setText(current.manager);
String phone= (String) new KerashDao(context).JobinfoGetValue(current.job_id.toString(),new KerashDao(context).SettingGetValue("phone").toString());
myHolder.phonecall.setText(phone.toString());
try {
if(!current.image.isEmpty()) {
Picasso.with(context)
.load(current.image)
.placeholder(R.drawable.icn_loading)
.into(myHolder.picture, new Callback() {
@Override
public void onSuccess() {myHolder.picture.setVisibility(View.VISIBLE);}
@Override
public void onError() {
myHolder.picture.setVisibility(View.GONE);
}
});
}
}catch (Exception ex){Log.i("JobAdapter2",ex.getMessage().toString()+"");}
}
RecyclerView
回收代表每一行的视图。这意味着给定的视图一旦滚出屏幕,就会被另一行重新使用。由于您在某个时候将图像加载到该视图中,它会一直存在直到您清除它。
在您的 if(!current.image.isEmpty())
语句中添加一个 else
子句,以清除 ImageView
中的图像。