0

i do have a fragment and in the fragment a textview. I want that this textview reacts to some events. For example i do have a variable and i want that my textview shows the variabel. This works pretty fine so far, but if my variable changes my textview does not! So i guess there must be something like an eventlistener but i haven't found one yet. Can't imagine that it is hard to solve that problem, but i couldn't find the right listener. Or is there maybe another recept? Actually i don't think that it makes a big differents, if the textview is in a fragment or an normal activity!?

THX

Charles1
  • 57
  • 8
  • You can't. You have to every time call `textView.setText()` when the value of variable will be change. Android View doesn't automatically refresh as your variables are changed.. – user370305 Nov 28 '12 at 13:22
  • Dam... in my textview should be written how many articles someone bought... so everytime somebody press a button to buy an article i need that update in my fragment... how can i do that – Charles1 Nov 28 '12 at 13:26
  • Ok, If you make a Listener for when your Variable's value changes then you have to call `TextView's` `setText()` method. – user370305 Nov 28 '12 at 13:28
  • How can i do it??? I never did anything like that before? I mean how can i write my own listener class??? – Charles1 Nov 30 '12 at 07:35
  • Look at the SO Question http://stackoverflow.com/questions/9387000/android-execute-code-on-variable-change – user370305 Nov 30 '12 at 07:39
  • Yeah... it worked really fine! The only problem is if i am setting my variable from one activity, my textview is updated at once. But if i go from my activity to a next activity and set my variable in that second activity and than return to my old activity, it is not updated : ( What do i have to do??? – Charles1 Dec 01 '12 at 07:43

0 Answers0