Android Question AHSwipeToRefresh library with XCustomListView Error (Solved)

A0_2_A7

Member
Licensed User
Hi, i'm trying to use the AHSwipeToRefresh library with XCustomListView but it gives me the following error. Is there any way to use this fantastic library with XCustomListView?

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 39 (Main)
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:5034)
    at android.view.ViewGroup.addView(ViewGroup.java:4865)
    at android.view.ViewGroup.addView(ViewGroup.java:4805)
    at android.view.ViewGroup.addView(ViewGroup.java:4778)
    at de.amberhome.strefresh.AHSwipeToRefresh.AddView(AHSwipeToRefresh.java:97)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Activity (main) Resume **
 

Attachments

  • AHSwipeXCustomListView.zip
    10 KB · Views: 277

A0_2_A7

Member
Licensed User
Ok, the solution was to remove the view of the activity before.

B4X:
'It is not possible to add child objects to custom views in the designer.
    'So we have to add the listview manually here.
    RemoveView(CustomListView1.AsView)
    STR.AddView(CustomListView1.AsView)

call this sub:

B4X:
Sub RemoveView (V As View)
    For i = 0 To Activity.NumberOfViews - 1
        If Activity.GetView(i) = V Then
            Activity.RemoveViewAt(i)
            Exit
        End If
    Next
End Sub

I upload the corrected project.

Regards.
 

Attachments

  • AHSwipeXCustomListView_OK.zip
    10.1 KB · Views: 287
Upvote 0
Top