0

如果 value= x 我想改变 imageview 的可见性

但我在 Eclipse 上有错误消息。

这是我的java的一部分

                if (success == 1) {
                    // products found
                    // Getting Array of Products
                    products = json.getJSONArray(TAG_PRODUCTS);

                    // looping through All Products
                    for (int i = 0; i < products.length(); i++) {
                        JSONObject c = products.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_PID);
                        String name = c.getString(TAG_NAME);
                        String price = c.getString(TAG_PRICE);
                        String cu = c.getString(TAG_CU);
                        /////////////
                                                ///HERE THE BUG////
                        if (cu == "1"){

                            cu = "oui";
                        }
                        else {  
                            ImageView image_A_wrong = (ImageView) findViewById(R.id.imageView1);
                            image_A_wrong.setVisibility(View.GONE);

                        }

这里是我的 xml 文件

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/quo100px"
        android:visibility="gone" />

tks提前为您提供帮助

4

3 回答 3

1

使用cu.equals("1")而不是cu == "1",你会没事的

于 2013-04-04T12:53:57.130 回答
1

为此,您必须检查是否使用字符串进行压缩而不是使用 .equalsIgnoreCase("") 函数,否则使用 == 进行比较。

于 2016-08-22T13:25:02.937 回答
0

您正在检查 aString在这种情况下.equals("your_constraint")使用了。

所以,改变这个:

if (cu == "1") {
    cu = "oui";
} else {
    ImageView image_A_wrong = (ImageView) findViewById(R.id.imageView1);
    image_A_wrong.setVisibility(View.GONE);
}

对此:

if (cu.equals("1")) {
    cu = "oui";
} else {
    ImageView image_A_wrong = (ImageView) findViewById(R.id.imageView1);
    image_A_wrong.setVisibility(View.GONE);
}
于 2013-04-04T12:54:23.660 回答