我已经使用了这个代码超过6个月,但是它已经花了几个小时不能调用getview,我不知道为什么。我记录了适配器大小,它有1项,但getView没有调用。
我还在getCount()中记录了适配器大小,它有1个项目。这是代码:
public class ListAdapter extends BaseAdapter {
Activity activity;
public ArrayList<HashMap<String, String>> list;
public ListAdapter(Activity activity, ArrayList<HashMap<String, String>> list) {
super();
this.activity = (Activity) activity;
this.list = list;
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return list.get(position);
}
public void addAll(ArrayList<HashMap<String, String>> result) {
if (this.list == null) {
this.list = result;
} else {
this.list.addAll(result);
}
notifyDataSetChanged();
}
public HashMap<String, String> geting(int position) {
return list.get(position);
}
public long getItemId(int arg0) {
return 0;
}
private class ViewHolder {
ImageView img;
}
public View getView(int position, View convertView, ViewGroup parent) {
Log.v("this","comes");
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
if(isTablet)
convertView = inflater.inflate(R.layout.ads_ekhtesasi_grid, null);
else
convertView = inflater.inflate(R.layout.ads_ekhtesasi, null);
holder = new ViewHolder();
holder.img = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
item = list.get(position);
Log.v("this",item.get("img"));
return convertView;
}
public void clear() {
if (this.list.size() > 0)
this.list.clear();
}
}
正如你所看到的,我已经在getview的第一行登录,但它没有进入。
你可以帮帮我吗?那是为什么?答案 0 :(得分:0)
你忘记了@Override。 将此方法标记为@Override,它将正常工作: public int getCount() public Object getItem(int position) public View getView(int position,View convertView,ViewGroup parent)
public class ListAdapter extends BaseAdapter {
Activity activity;
public ArrayList<HashMap<String, String>> list;
public ListAdapter(Activity activity, ArrayList<HashMap<String, String>> list) {
super();
this.activity = (Activity) activity;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
public void addAll(ArrayList<HashMap<String, String>> result) {
if (this.list == null) {
this.list = result;
} else {
this.list.addAll(result);
}
notifyDataSetChanged();
}
public HashMap<String, String> geting(int position) {
return list.get(position);
}
public long getItemId(int arg0) {
return 0;
}
private class ViewHolder {
ImageView img;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.v("this","comes");
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
if(isTablet)
convertView = inflater.inflate(R.layout.ads_ekhtesasi_grid, null);
else
convertView = inflater.inflate(R.layout.ads_ekhtesasi, null);
holder = new ViewHolder();
holder.img = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
item = list.get(position);
Log.v("this",item.get("img"));
return convertView;
}
public void clear() {
if (this.list.size() > 0)
this.list.clear();
}
}