[Question] Scrollview's

XverhelstX

Well-Known Member
Licensed User
Longtime User
Heey,

I want to add text to my ScrollView everytime something happens but it will go under eachother.

So I have a Service: Interceptor.

there I count my intCounter + 1 for every message I receive.
and store the text: "One new message arrived" in strNotifications.

in my Main Activity, in a timer1_tick, I want to add the text to the ScrollView.

B4X:
   For i = 0 To Interceptor.intCounter
      Dim lblNotifications As Label
      lblNotifications.Initialize("")
      lblNotifications.TextColor = Colors.white
      lblNotifications.Text = Interceptor.strNotifications
      ScrollView1.Panel.AddView(lblNotifications, 10, 10 + i * 10dip, ScrollView1.Width, 38dip)
   Next

Then everytime I receive a message, a message will appear on the scrollview. but now, when I want to read the message, I set the intCounter +1 and change the strNotifications in my service into "Reading message". then a new string will be added to the Scrollview, but than all the text will be changed, including the text above it.

So how do I keep the text then as the following:

B4X:
"One new message arrived"
"Reading message"
instead of
B4X:
"Reading message"
"Reading message"

Hope U can help me!
Thanks

XverhelstX
 

kickaha

Well-Known Member
Licensed User
Longtime User
What you have programmed is that every time timer1_tick is called, the scrollview has new labels added to it over the top of existing labels.

What you need to do is forget the timer, and add a new label everytime an event occurs, the following code should work:

B4X:
   Dim lblNotifications As Label
   lblNotifications.Initialize("")
   lblNotifications.TextColor = Colors.white
   lblNotifications.Text = Interceptor.strNotifications
   ScrollView1.Panel.AddView(lblNotifications, 10, 10 + ScrollView1.Panel.NumberOfViews * 10dip, ScrollView1.Width, 38dip)
You call this after setting strNotifications with the required message, and it will add the message to the bottom of the scrollview.
 
Upvote 0
Top