0

In my Activity A, I have 8 toggle buttons that the background of them is set within the layout xml to an xml file to change the pictures on change state. After choosing 4 of them, the image strings are saved to a SQLite database. In my Activity B, I am trying to set the background of another set of toggle buttons from the choices made from Activity A. Each of the 8 original toggle buttons has 4 images associated with them. So i have 32 change state xmls but when I try to set the background during if statement, they do not show. The original image strings are saved to a sqlite database in (A) and then retrieved in (B). I know the database retrieval works, its just setting the toggle button background based on the value from the database.

JAVA

if(imgData1 == "img1.png")
    {
        tbTest1.setBackgroundResource(R.drawable.test1);
        tbTest2.setBackgroundResource(R.drawable.test2);
        tbTest3.setBackgroundResource(R.drawable.test3);
        tbTest4.setBackgroundResource(R.drawable.test4);
    }
    else if(imgData1 == "img2.png")
    {
        tbTest1.setBackgroundResource(R.drawable.test5);
        tbTest2.setBackgroundResource(R.drawable.test6);
        tbTest3.setBackgroundResource(R.drawable.test7);
        tbTest4.setBackgroundResource(R.drawable.test8);
    }
    else if(imgData1 == "img3.png")
    {
        tbTest1.setBackgroundResource(R.drawable.test9);
        tbTest2.setBackgroundResource(R.drawable.test10);
        tbTest3.setBackgroundResource(R.drawable.test11);
        tbTest4.setBackgroundResource(R.drawable.test12);
    }
    else if(imgData1 == "img4.png")
    {
        tbTest1.setBackgroundResource(R.drawable.test13);
        tbTest2.setBackgroundResource(R.drawable.test14);
        tbTest3.setBackgroundResource(R.drawable.test15);
        tbTest4.setBackgroundResource(R.drawable.test16);
    }
johnnysheps
  • 37
  • 1
  • 1
  • 7
  • 1
    don't use `==` to compare strings, use `.equals()` – Apurva Mar 19 '15 at 12:18
  • Is my bad string comparison what's causing the xmls to not show? – johnnysheps Mar 19 '15 at 12:54
  • 1
    @SeanHall : Fix your comparison approach and then see what happens. If necessary, post a new question. As things stand, the code you posted won't work. Using `if(imgData1 == "img1.png")` will *NEVER* return `true`. Please read the answer to the question I used to mark yours as a duplicate. – Squonk Mar 19 '15 at 13:00
  • 1
    That was exactly the problem. Stupid rookie mistake lol. Thank you Squonk – johnnysheps Mar 19 '15 at 13:21
  • @SeanHall : Not such a bad mistake. I came to Java from C# (Microsoft's rip-off interpretation of Java). In C#, using `==` to compare string values actually works because the run-time checks for object type. I had a few problems with string comparison in Java as a result of that and learned my lesson. C# actually has a `String.equals(...)` method which I now find myself using on the occasions I have to do C# programming. – Squonk Mar 19 '15 at 13:51

0 Answers0