ListView的每個item上都可能有時間不同的Timer定時器,每個item上可能顯示圖片(有活動顯示圖片)。
我填充了兩種不同的item布局,一種帶背景圖片的,一種不帶。如果任意item有倒計時,則Timer每秒調用一次adapter.notifyDataSetChanged。
現在的問題是圖片偶爾、是偶爾可能會閃爍(個人猜測和Timer相關)。
product_newYear_img(寬度match_parent,高40dp),設置tag,但好像扔無濟於事。求大神解決。
adapter相關代碼如下。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Log.i("TAG", "getView"+position);
if (convertView == null) {
Log.i("TAG", "convertView == null"+position);
holder = new ViewHolder();
if (getItemViewType(position) == 0) {// 有活動
convertView = mInflater.inflate(R.layout.homepage_product_list_item_activity, null);
holder.product_newYear_img = (ImageView) convertView.findViewById(R.id.product_newYear_img);
} else {
convertView = mInflater.inflate(R.layout.homepage_product_list_item, null);
}
holder.product_title = (TextView) convertView.findViewById(R.id.product_title);
holder.product_time = (TextView) convertView.findViewById(R.id.product_time);
holder.product_apr_title = (TextView) convertView.findViewById(R.id.product_apr_title);
holder.product_apr = (TextView) convertView.findViewById(R.id.product_apr);
holder.product_time_limit = (TextView) convertView.findViewById(R.id.product_time_limit);
holder.product_lowest = (TextView) convertView.findViewById(R.id.product_lowest);
holder.product_progress = (RoundProgressBar) convertView.findViewById(R.id.product_progress);
holder.product_status = (TextView) convertView.findViewById(R.id.product_status);
holder.product_title_bt = (TextView) convertView.findViewById(R.id.product_title_bt);
holder.product_relayout = (RelativeLayout) convertView.findViewById(R.id.product_relayout);
holder.product_blankSpace = convertView.findViewById(R.id.product_blankSpace);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (getItemViewType(position) == 0) {//有活動
if (!getItem(position).getActivitylist().equals(holder.product_relayout.getTag())) {
mBitmapUtils.display(holder.product_relayout, getItem(position).getActivitylist());
holder.product_relayout.setTag(getItem(position).getActivitylist());
}
if (!getItem(position).getActivitylist().equals(holder.product_newYear_img.getTag())) {
mBitmapUtils.display(holder.product_newYear_img, getItem(position).getActivitybg());
holder.product_newYear_img.setTag(getItem(position).getActivitybg());
}
// mBitmapUtils.display(holder.product_relayout, getItem(position).getActivitylist());
// mBitmapUtils.display(holder.product_newYear_img, getItem(position).getActivitybg());
}else{
holder.product_relayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.item_selector));
}
// 有補貼
if (TextUtils.isEmpty(getItem(position).getApr_add())||getItem(position).getApr_add().equals(Constant.NUMBER_0)||Double.valueOf(getItem(position).getApr_add())==0) {
holder.product_apr.setText(context.getString(R.string.product_apr_t,getItem(position).getApr()));
holder.product_title_bt.setVisibility(View.GONE);
}else{
holder.product_apr.setText(context.getString(R.string.product_apr_total,getItem(position).getApr(),getItem(position).getApr_add()));
holder.product_title_bt.setVisibility(View.VISIBLE);
}
holder.product_title.setText(getItem(position).getName());
if (!TextUtils.isEmpty(getItem(position).getSurplus_time())) {
Log.i("TAG", "getItem(position).getSurplus_time()="+getItem(position).getSurplus_time());
holder.product_time.setText(getItem(position).getSurplus_time());
}
holder.product_apr_title.setText(context.getString(R.string.product_apr_title));
holder.product_time_limit.setText(context.getString(R.string.product_time_limit, getItem(position).getTime_limit()));
holder.product_lowest.setText(context.getString(R.string.product_lowest, DisplayFormat.intFormat(getItem(position).getLowest_account())));
holder.product_status.setText(Utils.getProductStatus(type, getItem(position).getStatus(), getItem(position).getScales()));
if (holder.product_status.getText().equals(Constant.PRODUCT_STATUS_HKZ1) ||
holder.product_status.getText().equals(Constant.PRODUCT_STATUS_HKZ2)) {
holder.product_progress.setCricleProgressColor(Color.LTGRAY);
} else {
holder.product_progress.setCricleProgressColor(context.getResources().getColor(R.color.rpb_roundProgressColor));
}
holder.product_progress.setProgress(Float.valueOf(getItem(position).getScales()));
return convertView;
}
自己解決了( !getItem(position).getActivitylist().equals(holder.product_newYear_img.getTag())
這裡寫錯了應該是( !getItem(position).getActivitybg().equals(holder.product_newYear_img.getTag())
大家不要像我一樣犯這種低級錯誤~