iOS Question changing colours with a timer. partly works partly doesn't

Albi

Active Member
Licensed User
Longtime User
Hello.
I have this code. It's very strange. I have some textviews which act as buttons. When the user presses them the background changes colour and the text colour also changes. it waits 2 seconds and then loads the next set of buttons, resetting all the colours.
However, the background ALWAYS changes, and the text colour almost never changes.
B4X:
Sub txvQ_Click
    Dim txv As TextView
    txv = Sender
    Dim theInt As Int
    theInt = txv.Tag
    txv.TextColor = Colors.RGB(255,250,250)
    txv.Color = Colors.RGB(132,0,0)
    timer2.Enabled = True
End Sub
B4X:
Sub timer2_Tick
    timer2.Enabled = False
    LoadPage2
End Sub
LoadPage 2 is where things get reset. If I take out the resetting of text colour to black, all the text remains white. So it's changing but not showing up. When I step through the code it all works fine.
What I can't understand is why the background colour changes perfectly, but the textcolour doesn't!?

I tried changing the order that they occur in this routine, switching it to rgb values to match the .color but it didn't make any difference.

Also, strangely, the first button press when loading the app always turns the text white. If there are only two 'buttons' loaded, then pressing the second one always turns the text white. Any other 'buttons' pressed only change the background colour.

Same occurs in debug and release modes.
Any ideas to try?
 

Albi

Active Member
Licensed User
Longtime User
sorry. I was trying to keep it as brief as possible. LoadPage2 loads new questions in this way:
B4X:
Sub LoadPage2
    'set answers
    Dim j As Long
    For j = 1 To questionsData.q(currentQ).NoOfAnswers
        lblQuestion.text = questionsData.q(currentQ).getQuestion
        userChoice(j).Visible = True
        userChoice(j).Color = Colors.Transparent
        userChoice(j).TextColor = Colors.Black
        userChoice(j).Text = questionsData.q(currentQ).getAnswers(j-1)
    Next   
End Sub

The colour parts reset the questions lovely. the textcolour ones do too! (when i comment them out, the textcolour remains white for j in future)
 
Upvote 0

Albi

Active Member
Licensed User
Longtime User
Hello,
yes, i've attached as minimal an example as i can.
the first answer, the text turns white, and backgrounds red. thereafter, just the backgrounds change colour. except when there is a choice of 2 answers, when the second of the two will always turn the text white. very odd indeed.

(also, please not that restarting the app often throws nullpointerexceptions. I havent worked out why, but cleaning the project and restarting always resolves the issue. I expect that that is something to do with my class, but i don't know what it is yet)

thanks very much for having a look at this!
 

Attachments

  • weirdEx.zip
    57.3 KB · Views: 246
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry for answering only today, but the last days I did some other work.

I tested your program and see also the strange behaviour.
I get also the NullPointerExeption, depending on the change of the TextColor. Very strange.
Changing the color in this line userChoice(j).TextColor = Colors.Black raises the NullPointerExeption.

I have tried several things with no success.

I think Erel should have a look at this problem.
 
Upvote 0

Albi

Active Member
Licensed User
Longtime User
thanks both for your help!

ps I find changing any line which includes my class will cause the null pointer exception
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
About the text color. It seems like a bug in iOS. You can workaround it with this code:
B4X:
Dim s As String = txv.Text
txv.Text = ""
txv.Text = s

The NullPointerException error is fixed for the next update.

I recommend you to switch to a Map or List instead of an array. It will fix this issue and it will be easier to modify in the future.
 
Upvote 0
Top