spinner If Strings** == not working

后端 未结 2 1883
面向向阳花
面向向阳花 2021-01-23 21:54

Why is this not working ?!

if(itemx == \"Test number item 0\")
    {
    Log.i(\"Dropdown\", \"inside if\");
    us_lo_ans_hold.setText(\"0x\");
    }; 
<         


        
相关标签:
2条回答
  • 2021-01-23 22:04

    Never compare Strings with ==, use equals:

    if(itemx.equals("Test item 0")){...
    

    As for onNothingSelected, the documentation states it will be called for example if you delete the selected item from your adapter.

    0 讨论(0)
  • 2021-01-23 22:24

    If your itemx is a variable then you cant compare two strings with ==. Use instead items.equals("Test number item 0");

    == compares objects and equals() compare string values. Take a look a this post.

    0 讨论(0)
提交回复
热议问题