0

I am new to Android Development. I've been spending a lot of time trying to have my ExpandableListView checkbox states saved to the Sharedpreferences, but I am having so much trouble with it. I am coming to an end to the solution, and I think the only way to keep the groupPosition and childPosition in the SharedPreferences is to use Json arraylist with Switch-Case. Since Json only allows me to remove only 1 index, there is no way I can remove the check state without this switch-case statement.

The problem is I have to make a switch-case with the following:

        case 0:
            GroupPosition = 10 + GroupPosition;
            break;
        case 1:
            GroupPosition = 20 + GroupPosition;
            break;
        case 2:
            GroupPosition = 30 + GroupPosition;
            break;
        case 3:
            GroupPosition = 40 + GroupPosition;
            break; 

.......

.......

        case 100:
            GroupPosition = ...... + GroupPosition;
            break;

My question is:

How does this affect the performance?

Thank you

YRTM2014
  • 165
  • 1
  • 8

1 Answers1

0

The switch case statement is only of developer convenience (at least in android).

After it is compiled, all switch statement get translated into if statements.

So just use which ever pleases you.

But for your case why don't you don't something like (guessing from the pattern in your code)

int i = value;
value = (value + 1) * 10 + GroupPosition;
PrivatMamtora
  • 2,072
  • 2
  • 19
  • 29
  • I saw G. Blake Meike and your solution, and I fixed my code. Now I have 99 less lines of code! I guess I was so frustrated and my mind just went out the window! I totally forgot about multiply! It won't let me vote you up until I am higher in rank. Sorry and thanks a bunch – YRTM2014 Aug 25 '14 at 04:07
  • 1
    Always DRY (Don't repeat yourself). If your conditional statements go above 5-10 (15 max), it is time to start thinking differently. – PrivatMamtora Aug 25 '14 at 05:21