Hide Dynamically Added Buttons Based On An If Statement
Solution 1:
The problem is with this block of code:
if (battle.equals(false)) {
battleBtn.setVisibility(View.INVISIBLE);
}
if (ingame.equals(false)) {
newgameBtn.setVisibility(View.INVISIBLE);
}
As you're aware that ListView items are recycled (that's why you should use a ViewHolder), you also need to set the buttons to View.VISIBLE when the condition is true.
Your code should look like this:
if (battle.equals(false)) {
battleBtn.setVisibility(View.INVISIBLE);
} else {
battleBtn.setVisibility(View.VISIBLE);
if (ingame.equals(false)) {
newgameBtn.setVisibility(View.INVISIBLE);
} else {
newgameBtn.setVisibility(View.VISIBLE);
}
Solution 2:
I don't know logic of your application but I see error and two possible solution.
Because you looping over
victimArrayand becauseNetPlay.myIdis in the middle of array you always get battle asfalse. So you should initiatebattlewithfalseand break as soon as it's true.I assume you should change check:
NetPlay.victimArray[i].equals(NetPlay.myId)
to
NetPlay.victimArray[i].equals(friend.id)
And similar for another condition.
I would also suggest you to use HashSet instead of primitive victimArray. It will give you more optimal search with contains method instead of looping.
Post a Comment for "Hide Dynamically Added Buttons Based On An If Statement"