0

Situation:

I have implemented the code suggested in Android execute code on variable change

brief summary of above answer: A class (IntStoreValue) that stores an int and a listener, and proposes an interface for listening to changes in this int && A custom UI item (in this case a TextView) that implements the above interface and applies setText() when this int is changed.

I implemented this solution by setting this custom textview to listen to a public IntStoreValue constantly modified in my GLSurfaceView renderer class.

This causes a view.ViewRootImpl$CalledFromWrongThreadException. (trying to access UI from outside UI thread)...

This I can live with / understand...

What I don't understand, is why I am able to make this solution work with a custom SeekBar / ProgressBar using setProgress(int newValue) in the onIntChanged interface method...?

I used this "loophole" to make a normal TextView setText() onProgressChanged of my custom seekBar...

Why does this work with these widget.Bar items and not with TextViews?

I don't mind using this "SeekBar pass-through" loophole, but I would like to know why I cannot directly use the TV solution...

Thanks!

1 Answer 1

0

GLSurfaceView creates a separate rendering thread. You try to change the value of a variable you created on main thread from GLSurfaceView rendering thread.

Sign up to request clarification or add additional context in comments.

3 Comments

So I'm guessing setProgress() in SeekBar and ProgressBar indirectly make their changes to the UI, whereas TextView's setText() applies the transformation directly? I was just wondering why some changes to UI (setProgress) work from outside the main thread, and others (SetText) do not... But thanks for info anyhow :D!
The problem is you changing state which you created on main thread from GLSurfaceView rendering thread. There are ways to update UIThread state from another thread.
I still don't know why it works for SeekBar/ProgressBar.setProgress() and not for TextView/Button.setText()... This has been my question all along. As I have stated, I made it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.