已經過了3-4個小時,我仍然無法弄清楚爲什麼我的imageView的顏色會自動改變,我幾乎做了所有事情。這裏是getList的自定義代碼的代碼清單setColorFilter在自定義列表適配器中不工作correclty?
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.post_list_adapter, null);
viewHolder = new ViewHolder();
viewHolder.des = (TextView) convertView.findViewById(R.id.textView_des);
viewHolder.like = (TextView) convertView.findViewById(R.id.tv_like);
viewHolder.name = (TextView) convertView.findViewById(R.id.textView_name);
viewHolder.dislike = (TextView) convertView.findViewById(R.id.tv_dislike);
viewHolder.iv_photo = (ImageView) convertView.findViewById(R.id.imageView);
viewHolder.iv_dislike = (ImageView) convertView.findViewById(R.id.iv_dislike);
viewHolder.iv_like = (ImageView) convertView.findViewById(R.id.imageView_like);
viewHolder.iv_pic = (CircleImageView) convertView.findViewById(R.id.profile_image);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Picasso.with(context).load("url here").into(viewHolder.iv_photo);
Picasso.with(context).load("url here").into(viewHolder.iv_pic);
if (data.get(position).isLiked)
viewHolder.iv_like.setColorFilter(Color.parseColor("#00ff00"));
if (data.get(position).isDisliked)
viewHolder.iv_dislike.setColorFilter(Color.parseColor("#00ff00"));
viewHolder.des.setText(data.get(position).getPost_des());
viewHolder.name.setText(data.get(position).getName());
viewHolder.like.setText(data.get(position).getLikes());
viewHolder.dislike.setText(data.get(position).getDislikes());
viewHolder.iv_like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.image_anim));
if (data.get(position).isLiked) {
data.get(position).setLiked(false);
viewHolder.iv_like.setColorFilter(Color.parseColor("#000000"));
} else if (data.get(position).isDisliked) {
data.get(position).setLiked(true);
data.get(position).setDisliked(false);
viewHolder.iv_like.setColorFilter(Color.parseColor("#00ff00"));
viewHolder.iv_dislike.setColorFilter(Color.parseColor("#000000"));
} else {
data.get(position).setLiked(true);
viewHolder.iv_like.setColorFilter(Color.parseColor("#00ff00"));
}
}
});
viewHolder.iv_dislike.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.image_anim));
if (data.get(position).isDisliked) {
data.get(position).setDisliked(false);
viewHolder.iv_dislike.setColorFilter(Color.parseColor("#000000"));
} else if (data.get(position).isLiked) {
data.get(position).setLiked(false);
data.get(position).setDisliked(true);
viewHolder.iv_like.setColorFilter(Color.parseColor("#000000"));
viewHolder.iv_dislike.setColorFilter(Color.parseColor("#00ff00"));
} else {
data.get(position).setDisliked(true);
viewHolder.iv_dislike.setColorFilter(Color.parseColor("#00ff00"));
}
}
});
return convertView;
}
除了setColorfilter我所有的代碼都正常工作。
顯示實際結果和預期結果。或者至少顯示實際結果,並解釋什麼是錯的。 –
call'viewHolder.iv_like.setColorFilter(null); viewHolder.iv_dislike.setColorFilter(null)''在兩個'Picasso.with(...)'後面調用 – pskink
謝謝@pskink ..它的工作.. :-) – Amar