简体   繁体   English

IF语句不适用于ListView项目android

[英]IF statement doesn't work on ListView item android

ListView is generated from JSON with boolean getExpired . ListView是使用boolean getExpiredJSON生成的。 if getExpired() is TRUE , then textColor should be changed. 如果getExpired()TRUE ,则应该更改textColor but it set on list position even if == FALSE 但即使if == FALSE它也会设置在列表位置

Why 1st position is changed, if getExpired is FALSE on this item? 如果此项目的getExpiredFALSE ,为什么更改第一个位置?

this is my getView 这是我的getView

public View getView(int position, View convertView, ViewGroup parent) {

    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        if (item.getExpired()) {
            vh.imageView.setColorFilter(filter);
            vh.profilePhoto.setColorFilter(filter);
            vh.expired.setVisibility(View.VISIBLE);
            vh.username.setTextColor(Color.parseColor("#76808D"));
        }
    return vh.rootView;
}

If you're using the ViewHolder pattern you will be getting recycled views which have already have their views set to a certain state. 如果您使用的是ViewHolder模式,您将获得已将其视图设置为特定状态的回收视图。 In short, when using ViewHolder also use an else condition to set your view states how you want them to be. 简而言之,当使用ViewHolder时,还应使用else条件设置视图状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM