-2

In my app I'm trying to create a "loading screen" so the user knows what's happening and doesn't think the app is lagging when loading a new view upon releasing a button. I'm trying to have my "setViewVisibility" method run before the rest of the code but I can't seem to make it work. The way I have it set up right now is that there's an instance boolean that gets changed when one action is completed but for some reason it's not working. Any ideas on how I could fix this?

if(isLoadScreen == true){
   setViewVisibility(visibility.END);
   buttoni.setAlpha((float) 1);
   isLoadScreen = false;
}

if (isLoadScreen == false){
   setKeysList(list);
   startQuestion(keysList.get(0));
   currentQuestion = 0;
   isLoadScreen = true;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
CarbonZonda
  • 167
  • 2
  • 11
  • Seems like you need a [splash screen](http://stackoverflow.com/questions/22599508/how-do-i-show-a-splash-screen-in-android/22599557#22599557) – Onik Apr 07 '17 at 22:48
  • 1
    `if (isLoadScreen == false)` compares a `boolean` to a `boolean` to get a `boolean`, which is redundantly repetitive and superfluous. – Lew Bloch Apr 08 '17 at 08:25

1 Answers1

0

Your second block is always executed because isLoadScreen is always false at that point. You need to use else instead of if to get the behavior you want.

if (isLoadScreen == false){ //isLoadScreen is always false here - just use else instead
    setKeysList(list);
    startQuestion(keysList.get(0));
    currentQuestion = 0;
    isLoadScreen = true;
}

That said, there are better ways to create splash/loading screens - this question How do I make a splash screen? might provide some hints.

Community
  • 1
  • 1
Hulk
  • 6,399
  • 1
  • 30
  • 52
  • @JawadLeWywadi what do you mean? I just pointed out that `isLoadScreen` is always true when evaluating the condition of the second `if` given the OPs code - do you think I'm mistaken? – Hulk Apr 08 '17 at 06:58
  • @JawadLeWywadi I agree it should be closed - the reason being (for me) that it was caused by a trivial error that has nothing to do with the question. I might have pointed the trivial error out in a comment, but I chose the answer form. – Hulk Apr 09 '17 at 09:11