我已经在这个问题上待了一整天了,现在还无法解决。我希望你能提供帮助。我有一个自定义GridView,它在项目位置0上加载图像时出现问题:
我使用的是CustomGridView:ExpandableHeightGridView
我的适配器:
private final class SubCatListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener {
public JSONArray data;
private final Context context;
public SubCatListAdapter(Context context, JSONArray values) {
super();
this.context = context;
this.data = values;
}
// ...
class ViewHolder {
public TextView txtViewCatName;
public SimpleDraweeView imgLogo;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
ViewHolder viewHolder = null;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.gamification_subcat_adapter, parent, false);
viewHolder = new ViewHolder();
viewHolder.imgLogo = (SimpleDraweeView) rowView.findViewById(R.id.imgLogo);
viewHolder.txtViewCatName = (TextView) rowView.findViewById(R.id.txtViewCatName);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) rowView.getTag();
}
// data
try {
JSONObject node = getItem(position);
viewHolder.txtViewCatName.setText(Html.fromHtml(node.getString("CatName")).toString());
String catLogo = node.getString("CatLogoPath");
viewHolder.imgLogo.setImageURI(Uri.parse(catLogo));
Log.d("TAG", "position: " + position);
return rowView;
} catch (Exception e) {
e.printStackTrace();
return new View(context);
}
}
}
Log.d标记显示位置0被加载3次:
D/TAG﹕ position: 0
D/TAG﹕ position: 0
D/TAG﹕ position: 0
D/TAG﹕ position: 1
D/TAG﹕ position: 2
D/TAG﹕ position: 3
这是位于0,1,2,3位置的项目
请帮助~~我快死了...先谢谢了!
答案 0 :(得分:1)
private final class SubCatListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener {
public JSONArray data;
private final Context context;
public SubCatListAdapter(Context context, JSONArray values) {
super();
this.context = context;
this.data = values;
}
// ...
class ViewHolder {
public TextView txtViewCatName;
public SimpleDraweeView imgLogo;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.gamification_subcat_adapter, parent, false);
viewHolder.imgLogo = (SimpleDraweeView) rowView.findViewById(R.id.imgLogo);
viewHolder.txtViewCatName = (TextView) rowView.findViewById(R.id.txtViewCatName);
rowView.setTag(viewHolder);
// data
try {
JSONObject node = getItem(position);
viewHolder.txtViewCatName.setText(Html.fromHtml(node.getString("CatName")).toString());
String catLogo = node.getString("CatLogoPath");
viewHolder.imgLogo.setImageURI(Uri.parse(catLogo));
Log.d("TAG", "position: " + position);
return rowView;
} catch (Exception e) {
e.printStackTrace();
return new View(context);
}
}
}