Android Question How to use nested CustomListView

Status
Not open for further replies.

red30

Well-Known Member
Licensed User
Longtime User
I have a CustomListView "allclv" with 10 items. Each item contains lbl, btn and another CustomListView "clvPhoto".
Layout «Photo».png
How can I add clvPhoto, images? You need to add the image to the CustomListView in which the button is clicked.
If I try like this:
B4X:
Sub btnAddPhoto_Click
    indexAddPhoto=allclv.GetItemFromView(Sender)
  
    Dim i As Intent
    i.Initialize("android.intent.action.GET_CONTENT", "")
    i.PutExtra("android.intent.extra.ALLOW_MULTIPLE", True)
    i.SetType("image/*")
    StartActivityForResult(i)
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then 'resultCode = RESULT_OK
        Dim i As Intent = Args(1)
        Dim jo As JavaObject = i
        'Android 4.1+ (API 16)
        Dim uris As List
        uris.Initialize
        Dim clipdata As JavaObject = jo.RunMethod("getClipData", Null)
        If clipdata.IsInitialized Then
            Dim count As Int = clipdata.RunMethod("getItemCount", Null)
            For i2 = 0 To count -1
                Dim item As JavaObject = clipdata.RunMethod("getItemAt", Array(i2))
                uris.Add(item.RunMethod("getUri", Null))
            Next
        Else
            uris.Add(i.GetData)
        End If
        Log(uris)
        For j=0 To uris.Size-1
      
            Dim pnl As B4XView = allclv.GetPanel(indexAddPhoto)
            Dim clv As CustomListView = pnl.GetView(1).Tag
          
            Dim p As B4XView = xui.CreatePanel("")
            p.SetLayoutAnimated(0, 0, 0, clvPhoto.AsView.Width/3, clvPhoto.AsView.Height)
            p.LoadLayout("iv")
            iv.Bitmap=xui.LoadBitmapResize("ContentDir", uris.Get(j), 100dip, 100dip, True)
            clv.Add(p,"")
        Next
    End If
    Return Null
End Sub

Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub
Then I get the error:
B4X:
Copying updated assets files (3)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
(ArrayList) [content://com.android.providers.media.documents/document/image%3A1451]
Error occurred on line: 93 (Main)
java.lang.RuntimeException: Method: _add not found in: java.lang.String
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:985)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:644)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:774)
    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 anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4j.object.JavaObject$1.invoke(JavaObject.java:237)
    at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
    at $Proxy0.ResultArrived(Unknown Source)
    at anywheresoftware.b4a.BA$4.run(BA.java:585)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:459)
    at b4a.example.main$ResumeMessage.run(main.java:313)
    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:6865)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
The application will be cross-platform. Therefore, if it is a library, I would like it to be B4X
 

Attachments

  • testPhotoCLV.zip
    12.4 KB · Views: 155

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a duplicate post.

 
Upvote 0
Status
Not open for further replies.
Top