Activity.AddView in Listview

R1cky

New Member
Licensed User
Longtime User
Hi!!
I'm a real beginner!! :confused:

I have i problem on my code.
-There is a service that wait sms with SMSinterceptor
-The Sub _MessageReceived in the Main read the number and if this match add this number to a listview.

All work, I can select form listview some item too, but when i change orientation the listview lost all text.
The only one difference with all examle si the position of .AddSingleLine(sometinig), mine is inside _MessageReceived sub.

Thank you very much!

Regards
Rick

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim notification1 As Notification
   Dim SI As SmsInterceptor

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Numero As Label
   Dim Testo As Label
   Dim Elencosms As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("GUIsms")
   SI.Initialize("SI")
   Elencosms.Initialize("Elencosms")
   Activity.AddView(Elencosms, 0, 0, 100%x, 100%y)
   End Sub

Sub Activity_Resume
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
End Sub


Sub SI_MessageReceived (From As String, Body As String) As Boolean
'   ToastMessageShow(From, True)
   If From = "+0123456789" Then
   Numero.text = From
   Testo.text = Body
   End If
   Elencosms.AddSingleLine(Body)
   Return True
   End Sub
Sub Elencosms_ItemClick (Position As Int, Value As Object)
    Testo.text = Value
End Sub
 

mc73

Well-Known Member
Licensed User
Longtime User
I think you should store any data received, in a file, from which you should restore once the activity_resume event is triggered by an orientation change.

note: just saw NJDude's reply, sorry I was writing at the same time :)
 
Upvote 0

R1cky

New Member
Licensed User
Longtime User
Thanks mc73 and NJDude for answer! ;)
But why in simple listview code work without problem and no store data is needed?

Bye
R

B4X:
Sub Process_Globals

End Sub

Sub Globals
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ListView1.Initialize("ListView1")
   Dim GD As GradientDrawable
   GD.Initialize("TR_BL", Array As Int(Colors.Gray, Colors.LightGray))
   Activity.Background = GD
   ListView1.ScrollingBackgroundColor = Colors.Transparent
   Dim Bitmap1 As Bitmap
   Bitmap1.Initialize(File.DirAssets, "button.gif")
   
   ListView1.SingleLineLayout.ItemHeight = 100dip
    ListView1.SingleLineLayout.Label.TextSize = 20
    ListView1.SingleLineLayout.Label.TextColor = Colors.Blue
    ListView1.SingleLineLayout.Label.Gravity = Gravity.CENTER
   ListView1.FastScrollEnabled = True
   For i = 1 To 500
      ListView1.AddSingleLine("Item #" & i)
      ListView1.AddTwoLines("Item #" & i, "This is the second line.")
      ListView1.AddTwoLinesAndBitmap("Item #" & i, "This is the second line.", Bitmap1)    
   Next
   Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
   Activity.Title = Value
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0
Top