Android Question AHSwipeToRefresh and CustomListView Issue

Haris Hafeez

Active Member
Licensed User
Hello everybody,

Was just going through a sample app for SwipeToRefresh using this as the source. The example worked well but when I changed the view from ListView to CustomListView, the app crashes when the CLV class tries to execute su.MeasureMultilineTextHeight(lbl, Text).

Is this a known issue or am I missing something here?

Exported project is attached.

Thanks.
 

Attachments

  • SwipeToRefresh.zip
    10.5 KB · Views: 158

Haris Hafeez

Active Member
Licensed User
I get this:
LogCat connected to: emulator-5554
--------- beginning of system
--------- beginning of main
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
Error occurred on line: 122 (CustomListView)
java.lang.IllegalArgumentException: Layout: -12 < 0
at android.text.Layout.<init>(Layout.java:139)
at android.text.StaticLayout.<init>(StaticLayout.java:105)
at android.text.StaticLayout.<init>(StaticLayout.java:91)
at android.text.StaticLayout.<init>(StaticLayout.java:69)
at android.text.StaticLayout.<init>(StaticLayout.java:49)
at anywheresoftware.b4a.objects.StringUtils.MeasureMultilineTextHeight(StringUtils.java:32)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:668)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:334)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:244)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
** Activity (main) Create, isFirst = true **
customlistview_insertattextitem (java line: 361)
java.lang.IllegalArgumentException: Layout: -12 < 0
at android.text.Layout.<init>(Layout.java:139)
at android.text.StaticLayout.<init>(StaticLayout.java:105)
at android.text.StaticLayout.<init>(StaticLayout.java:91)
at android.text.StaticLayout.<init>(StaticLayout.java:69)
at android.text.StaticLayout.<init>(StaticLayout.java:49)
at anywheresoftware.b4a.objects.StringUtils.MeasureMultilineTextHeight(StringUtils.java:32)
at de.amberhome.swiperefreshexample.customlistview._insertattextitem(customlistview.java:361)
at de.amberhome.swiperefreshexample.customlistview._addtextitem(customlistview.java:51)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:404)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:335)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.IllegalArgumentException: Layout: -12 < 0
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
main_refreshlistview (java line: 414)
java.lang.RuntimeException: Object should first be initialized (Panel).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:63)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:414)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:340)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.RuntimeException: Object should first be initialized (Panel).
** Activity (main) Create, isFirst = true **
main_refreshlistview (java line: 416)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3936)
at android.view.ViewGroup.addView(ViewGroup.java:3786)
at android.view.ViewGroup.addView(ViewGroup.java:3758)
at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:63)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:416)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:340)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
** Activity (main) Create, isFirst = true **
main_refreshlistview (java line: 412)
java.lang.RuntimeException: Object should first be initialized (ImageView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:412)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:335)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.RuntimeException: Object should first be initialized (ImageView).
** Activity (main) Create, isFirst = true **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory: 24
Downsampling image due to lack of memory: 48
--------- beginning of crash
** Activity (main) Create, isFirst = true **
main_refreshlistview (java line: 411)
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.height' on a null object reference
at anywheresoftware.b4a.objects.ViewWrapper.getHeight(ViewWrapper.java:143)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:411)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:335)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.height' on a null object reference
** Activity (main) Create, isFirst = true **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory: 24
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
Downsampling image due to lack of memory: 12
Downsampling image due to lack of memory: 24
** Activity (main) Create, isFirst = true **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 6
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (imagedownloader) Create **
** Service (imagedownloader) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = true **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activity2) Create, isFirst = false **
** Activity (activity2) Resume **
** Activity (activity2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
customlistview_insertattextitem (java line: 361)
java.lang.IllegalArgumentException: Layout: -12 < 0
at android.text.Layout.<init>(Layout.java:139)
at android.text.StaticLayout.<init>(StaticLayout.java:105)
at android.text.StaticLayout.<init>(StaticLayout.java:91)
at android.text.StaticLayout.<init>(StaticLayout.java:69)
at android.text.StaticLayout.<init>(StaticLayout.java:49)
at anywheresoftware.b4a.objects.StringUtils.MeasureMultilineTextHeight(StringUtils.java:32)
at de.amberhome.swiperefreshexample.customlistview._insertattextitem(customlistview.java:361)
at de.amberhome.swiperefreshexample.customlistview._addtextitem(customlistview.java:51)
at de.amberhome.swiperefreshexample.main._refreshlistview(main.java:404)
at de.amberhome.swiperefreshexample.main._activity_create(main.java:335)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.swiperefreshexample.main.afterFirstLayout(main.java:102)
at de.amberhome.swiperefreshexample.main.access$000(main.java:17)
at de.amberhome.swiperefreshexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.IllegalArgumentException: Layout: -12 < 0
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
No simply adding CLV to a panel doesn't create any issues. Also, CLV works with AHSwipeToRefresh when the standard Add method is used to add a panel to CLV. This is what I don't understand.

I suppose I will move this discussion over to the AHSwipeToRefresh thread or change this thread's title.
 
Upvote 0

frenkipi

Member
Licensed User
I have managed to get it working, but my sv_ScrollChnged method in clv is not called anymore

B4X:
Private Sub sv_ScrollChanged(Position As Int)
   If Position + sv.Height >= sv.Panel.Height Then
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems")
       Log(CallBack)     
     End If
   End If
End Sub

and I initialize it with

B4X:
clv3.Initialize("","clv3")

when watching log on other clvs without swipetorefresh on bottom page I get

class b4a.example.main

and when watching log on clvs with swipetorefresh on bottom page I don't get any log.

Any sugestions?

Regards!
 
Upvote 0

DonManfred

Expert
Licensed User
have you tried
B4X:
clv3.Initialize(me,"clv3")

Edit:
Must it not be

B4X:
clv1_ScrollChanged(Position As Int)
as you are setting the eventname to "clv1" and not to "sv"
 
Upvote 0

frenkipi

Member
Licensed User
OK, my initialize method is now like this

B4X:
clv3.Initialize(Me,"clv3")

and it's calling initialize method in my class CustomListView

B4X:
Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
    sv.Initialize2(0, "sv")
    items.Initialize
    panels.Initialize
   
    'these defaults will be used when the view is added by code
    dividerHeight = 2dip
    sv.Color = 0xFFD9D7DE
    DefaultTextColor = Colors.White
    DefaultTextSize = 16
    PressedDrawable.Initialize(0xFF7EB4FA, 2dip)
End Sub

and when debugging on my sv_ScrollChanged my sv.Height (scrollview) values is -2 all the time

B4X:
Private Sub sv_ScrollChanged(Position As Int)
    Log(Position)
    Log(sv.Height)
    Log(sv.Panel.Height)
   If Position + sv.Height >= sv.Panel.Height Then
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems")
      Log(CallBack)     
     End If
   End If
End Sub

On click method is working fine.

Any sugestions?
 
Upvote 0

frenkipi

Member
Licensed User
Here is my sample project, libs are in zip file. I hope you can help me.

Regards!
 

Attachments

  • CustomListView.zip
    95.4 KB · Views: 142
Upvote 0
Top