重:每个ListItem是属于ListItem自己的,不能够放到ViewHolder中,而是数据源每项的.
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.inbox_list_item, parent, false); holder = new ViewHolder(convertView); } else { holder = (ViewHolder) convertView.getTag(); } ReceiveBoxResponse.ListBean bean = list.get(position); holder.from_username.setText(bean.getFrom_username()); holder.content.setText(bean.getTitle()); holder.time.setText(bean.getCreate_time()); //是否已读 Object tag=holder.time.getTag(); if (tag == null) { QBadgeView qBadgeView=new QBadgeView(parent.getContext());// qBadgeView.bindTarget(holder.overlay_badge); qBadgeView.setBadgeGravity(Gravity.START | Gravity.TOP); if("0".equals(bean.getHas_read())) { qBadgeView.setBadgeNumber(1);////1:已读,0:未读 }else { qBadgeView.setBadgeNumber(0); } holder.time.setTag(qBadgeView); }else{ QBadgeView qQBadgeView=(QBadgeView)tag; if("0".equals(bean.getHas_read())) { qQBadgeView.setBadgeNumber(1);////1:已读,0:未读 }else { qQBadgeView.setBadgeNumber(0); } } if(mStateIsEdit){ holder.check_box.setVisibility(View.VISIBLE); if(bean.isState()){ holder.check_box.setChecked(true); }else{ holder.check_box.setChecked(false); } }else{ holder.check_box.setVisibility(View.GONE); } return convertView; }