Add lines with listview

grant1842

Active Member
Licensed User
Longtime User
1. I am trying to use the results of a search and add the results to a list view.
2. I need to take the item click of the list view and send that string to the widget service.

I seem to get no items from the search.
I can not seem to manually insert item to listbox

all so on the widgetService i am trying to get the value of (cities) form the Main activity useing call sub it does not work.

Thanks for any help with this.
I attached the export.

I am useing the ICOWorldForecast lib to searh for a city.

<<<<<<<<<<<<Main>>>>>>>>>>>>>>
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 lvCities As ListView
   Dim I As Int
End Sub

Sub Globals
    Dim cities As List
   Dim lvCities As ListView
   Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   Activity.LoadLayout("start")
   
   
   
   
   
'   
End Sub
Sub lvCities_ItemClick (Position As Int, Value As Object)
Dim edtCity As EditText
   Dim lvCities As ListView
'   CallSub(WidgetService, "RefreshData")
   WidgetService.str = lvCities.GetItem(Position)
'   Activity.Finish
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




Sub Button1_Click
Dim edtCity As EditText
   
   edtCity.Initialize("")
   lvCities.Initialize("")
   lvCities.Initialize("lvcities")
   
'   Manually insert item into ListView
   lvCities.AddSingleLine("Wise,Virgina")
   If edtCity.Text <> "" Then
   lvCities.Clear   
   
'   search using edtCity.Text
   cities =WidgetService.a.GetList("Wise,Va")
      ToastMessageShow(cities,True)   
      For I = 0 To cities.Size - 1
         lvCities.AddSingleLine(cities.Get(I))
         
      Next
   Else
      ToastMessageShow("Enter a city", True)
   End If
   Msgbox("Go to the home screen and add the Hello Widget.", "")
End Sub


<<<<<<<<<<<<<<<WidgetService>>>>>>>>>>>>>>>>>>
B4X:
'Service module
Sub Process_Globals
Dim a As ICOSWorldForecast
Dim str As String
Dim rv As RemoteViews
Dim mGetList As String   
Dim city As String
End Sub
Sub Service_Create
a.Initialize("a")
a.ApiKey="a8df9adcc5202329121911"
city= CallSub(Main,"cities")
a.CityName= city
rv = ConfigureHomeWidget("L1", "rv", 30, "ICOSForecastWeater")
End Sub

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

Sub rv_RequestUpdate
SetTime
rv.UpdateWidget
End Sub

Sub rv_Disabled
StopService("")
End Sub

Sub Service_Destroy
End Sub

Sub SetTime
rv.SetImage("ivicon",a.CCIcon)
rv.SetText("lbtemp", a.CCTempCelsius&"°")
'rv.SetText("lbcity", str)
End Sub

Any help would be GREAT to figure this out.
 

Attachments

  • lstview.zip
    13.8 KB · Views: 216

grant1842

Active Member
Licensed User
Longtime User
Thanks for the help I sorted the listbox items out.

I now have the problem of geting the service to work .
Once i run the code it compiles , but after i pick the city on the main activity , and go to desktop and install the widget i get error(has stopped unexpectedly, Please try again.
Why is this crashing ?
Thanks for your help with this.

<<<<<<<<<<<<<<Main Code>>>>>>>>>>>>
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 I As Int
End Sub

Sub Globals
    Dim cities As List
   Dim lvCities As ListView
   Dim Button1 As Button
   
   Dim a As ICOSWorldForecast
   Dim edtCity As EditText
   Dim i As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   Activity.LoadLayout("start")
   
   a.Initialize(a)
   a.ApiKey="a8df9adcc5202329121911"
   
   
   
'   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




Sub Button1_Click
   
   
   lvCities.Clear
   cities=a.GetList(edtCity.Text)
   ToastMessageShow(cities,True)
   For i = 0 To cities.Size -1
   lvCities.AddSingleLine(cities.Get(i))
   Next
   
'   Msgbox("Go to the home screen and add the Hello Widget.", "")
End Sub
      
   Sub lvCities_ItemClick (Position As Int, Value As Object)
   a.CityName=lvCities.GetItem(Position)
   ToastMessageShow(lvCities.GetItem(Position),True)
   

End Sub

<<<<<<<<<<<<<<<<Widget Service>>>>>>>>>>>>>>>>>
B4X:
'Service module
Sub Process_Globals
Dim a As ICOSWorldForecast
Dim str As String
Dim rv As RemoteViews
Dim mGetList As String   
Dim city As String
End Sub
Sub Service_Create
a.Initialize("a")
a.ApiKey="a8df9adcc5202329121911"
'city= CallSub(Main,"cities")
a.CityName= CallSub(Main,"lvCities.GetItem(Position)")
ToastMessageShow(CallSub(Main,"lvCities.GetItem(Position)"),True)
rv = ConfigureHomeWidget("L1", "rv", 30, "ICOSForecastWeater")
End Sub

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

Sub rv_RequestUpdate
SetTime
rv.UpdateWidget
End Sub

Sub rv_Disabled
StopService("")
End Sub

Sub Service_Destroy
End Sub

Sub SetTime
rv.SetImage("ivicon",a.CCIcon)
rv.SetText("lbtemp", a.CCTempCelsius&"°")
'rv.SetText("lbcity", str)
End Sub
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
Here is logs.

** Service (widgetservice) Create **


widgetservice_service_create (java line: 125)
java.lang.NullPointerException: CityName appear to be empty!!
at it.giuseppe.salvi.icos.library.weather.ICOSWorldForecastWrapper.setCityName(ICOSWorldForecastWrapper.java:141)
at anywheresoftware.b4a.samples.homewidgets.widgetservice._service_create(widgetservice.java:125)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.samples.homewidgets.widgetservice.onCreate(widgetservice.java:38)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1920)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)


at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to create service anywheresoftware.b4a.samples.homewidgets.widgetservice: java.lang.RuntimeException: java.lang.NullPointerException: CityName appear to be empty!!
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1930)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: CityName appear to be empty!!
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.samples.homewidgets.widgetservice.onCreate(widgetservice.java:38)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1920)
... 10 more
Caused by: java.lang.NullPointerException: CityName appear to be empty!!
at it.giuseppe.salvi.icos.library.weather.ICOSWorldForecastWrapper.setCityName(ICOSWorldForecastWrapper.java:141)
at anywheresoftware.b4a.samples.homewidgets.widgetservice._service_create(widgetservice.java:125)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
... 13 more




I see city name looks to be empty. I do not think i am using the call sub correctly.
Is there a differnt way to access a var on a different module ?
Thanks for your help.
 
Last edited:
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
error

Here is my code for callsubdelayed.
B4X:
a.CityName= CallSubDelayed(Main,"choose")

error.
Compiling code. Error
Error compiling program.
Error description: Cannot assign void value.
Occurred on line: 24
a.CityName= CallSubDelayed(Main,"choose")
Word: )

hitting-computer.gif
I do not understand why this will not compile.
Any help is much appreciated .

bang.gif
 
Last edited:
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
What is the recommended way to carry a var from 1 activity to another.
Mabie callsub stuff is not the right thing to do here.

Sent from my SCH-S720C using Tapatalk 2
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Declare the variable in Sub Process_Globals.
The variable is available in every activity.
If you declare it in the Main module:
Dim MyVar as Double

You can call this variable with Main.MyVar in any other Activity.
In the Main module you call it MyVar.

Best regards.
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
Thanks for the help I will try this when I get home later

Sent from my SCH-S720C using Tapatalk 2
 
Upvote 0
Top