【问题标题】:Android comparing strings [duplicate]Android比较字符串[重复]
【发布时间】:2013-07-21 13:32:18
【问题描述】:

这是我的代码,非常简单。

ImageView newphone = (ImageView) rowView.findViewById(R.id.newsign);
        System.out.println(BeanClass.get(position).newphone.toLowerCase());
        if (BeanClass.get(position).newphone.toLowerCase() == "no") {
            newphone.setVisibility(View.GONE);
        } else {
            newphone.setVisibility(View.VISIBLE);

        }

图像视图在列表视图中始终可见。 这是我的日志:

07-21 16:26:14.426: I/System.out(7480): no
07-21 16:26:14.496: I/System.out(7480): no
07-21 16:26:14.611: I/System.out(7480): no
07-21 16:26:14.896: I/System.out(7480): no
07-21 16:26:14.926: I/System.out(7480): no
07-21 16:26:14.946: I/System.out(7480): no
07-21 16:26:14.966: I/System.out(7480): no
07-21 16:26:14.991: I/System.out(7480): no
07-21 16:26:15.026: I/System.out(7480): no
07-21 16:26:15.041: I/System.out(7480): no
07-21 16:26:15.076: I/System.out(7480): no
07-21 16:26:15.091: I/System.out(7480): yes
07-21 16:26:15.126: I/System.out(7480): no
07-21 16:26:15.161: I/System.out(7480): no
07-21 16:26:15.196: I/System.out(7480): no
07-21 16:26:15.246: I/System.out(7480): no
07-21 16:26:15.276: I/System.out(7480): no
07-21 16:26:15.326: I/System.out(7480): no
07-21 16:26:15.396: I/System.out(7480): no
07-21 16:26:15.461: I/System.out(7480): no
07-21 16:26:15.541: I/System.out(7480): no
07-21 16:26:15.661: I/System.out(7480): no
07-21 16:26:15.696: I/System.out(7480): no
07-21 16:26:15.761: I/System.out(7480): yes
07-21 16:26:15.796: I/System.out(7480): no
07-21 16:26:15.841: I/System.out(7480): no
07-21 16:26:15.896: I/System.out(7480): no
07-21 16:26:15.961: I/System.out(7480): no
07-21 16:26:16.046: I/System.out(7480): no
07-21 16:26:16.111: I/System.out(7480): no
07-21 16:26:16.161: I/System.out(7480): no
07-21 16:26:16.181: I/System.out(7480): no
07-21 16:26:16.211: I/System.out(7480): no
07-21 16:26:16.241: I/System.out(7480): no
07-21 16:26:16.276: I/System.out(7480): no
07-21 16:26:16.311: I/System.out(7480): no
07-21 16:26:16.341: I/System.out(7480): no
07-21 16:26:16.376: I/System.out(7480): no
07-21 16:26:16.426: I/System.out(7480): no
07-21 16:26:16.476: I/System.out(7480): no
07-21 16:26:16.526: I/System.out(7480): yes
07-21 16:26:16.611: I/System.out(7480): no
07-21 16:26:16.696: I/System.out(7480): no
07-21 16:26:16.846: I/System.out(7480): no

我有一个自定义列表视图,其中包含某些元素。一切正常!只有这一个不知道为什么?任何建议/

【问题讨论】:

    标签: android json string android-listview


    【解决方案1】:

    使用equalsequalsIgnoreCase 来比较字符串。 == 运算符比较字符串的引用

    例如:

    String a = "astring";
    if (a.equals("astring")) {
    
    }
    

    【讨论】:

      【解决方案2】:

      == 通过引用比较对象。

      要确定两个不同的String 实例是否具有相同的值,请调用equals()

      【讨论】:

        猜你喜欢
        • 2013-04-15
        • 1970-01-01
        • 2012-09-26
        • 2018-07-09
        • 2017-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        相关资源
        最近更新 更多