Android Question need help (WIDGET)

ilan

Expert
Licensed User
Longtime User
hi

i want to get text from my label in my widget but i dont know how, please help me !!

something like if label1.text = "1" then 'do something else 'do something end if

B4X:
'Service module
Sub Process_Globals
    Dim rv As RemoteViews
    Dim imageFiles() As String
    Dim currentImage As Int
    Dim Timer1 As Timer
   
End Sub

Sub Service_Create

    rv = ConfigureHomeWidget("L1", "rv", 0, "שכרניק",True)
    Timer1.Initialize("timer1",1000)

End Sub

Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
   
End Sub

Sub rv_RequestUpdate
    SetTime
    rv.UpdateWidget
    Timer1.Enabled = True
End Sub

Sub rv_Disabled
    StopService("")
End Sub

Sub Service_Destroy

End Sub

Sub Timer1_Tick
  Timer1.Enabled = False
  rv_RequestUpdate
End Sub

Sub SetTime
    rv.SetText("time", DateTime.Time(DateTime.Now))
End Sub

Sub play_Click 'here is the problem !! i dont know how to get the text of label1 !

If label1.text = "1" Then
rv.SetImage("play", LoadBitmap(File.DirAssets, "pause.png"))
rv.SetText("label1", "0")
Else
rv.SetImage("play", LoadBitmap(File.DirAssets, "play.png"))
rv.SetText("label1", "q")
End If

Timer1.Enabled = True
   
End Sub
Sub stop_Click
   
End Sub'
 

ilan

Expert
Licensed User
Longtime User
Where are you setting the label text to "1"?

i dont, what i have posted is just to explain what i need not the real code, i just would like to know how i can get anything from the labels on the widget

like the time

dim timetxt as string

timetxt = time.text 'time is the label that show the time on the widget


thanx ;)

edit: do i maybe need to add SUB GLOBALS and declare there label1 or anything else and then use it? because i cannot declare label1 in Process_Globals and i cannot use label1, if i declare label1 in process_globals i get errors while try to run the app
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
thank you erel, thats what i did

i saved my string to a file and i read it back when i need.

but i dont understand why there is no way to read just from the text thats is shown in the widget

like if i have a label1 in my widget with the text 10

is there no way to read from this label? if i dont want to write and read always from files

like:

dim st as string
st = label1.text

thank you
 
Upvote 0
Top