Android Question CustomListView - change text on panel gadget child

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello everyone !

someone know how do I change the text of a label in a panel created in CustomListView?

this is the sub what create new customlistview item :

B4X:
Private Sub CreateItemProfile(Width As Int, Title As String, Description As String, FeedID As String, Banner As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 210dip
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 250dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    'p.LoadLayout("Card3")
    p.LoadLayout("search_profile")
    
    Label_nome.Text = Title
    Label_status.Text = Description

    'ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, 50%x,50%y , True))

    If (ProfileImg.IsInitialized = True) Then
        'CardsAmount = CardsAmount + 1
        'Feeds.Put(CardsAmount,ImageView1)
        'Log("ImageViewID = "&Feeds.Get(CardsAmount))
        ProfileImg.Put(ImageView1,"https://"&Banner)
    Else
        
        Msgbox("Erro de alocação de memória ! 0x0543f","Erro interno !")
        ExitApplication
        
    End If

    Return p
End Sub

this is the Design : http://prntscr.com/no74b6

i would like to change the text of " Label_status " , when lblAction is clicked in specific customlistview item...
 

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
dont works :c

this is the event sub

B4X:
Sub lblAction_Click
    Dim index As Int = CustomListView1.GetItemFromView(Sender)
    
    Log("lblAction is initialized ? : "&lblAction.IsInitialized)
    
    Dim pnl As B4XView = CustomListView1.GetPanel(0)
    Log(pnl.GetView(1))
End Sub

this is log error :
B4X:
Logger conectado a:  Xiaomi Redmi 6
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
lblAction is initialized ? : true
search_profile_lblaction_click (java line: 598)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:298)
    at com.partygo.coldbyte.search_profile._lblaction_click(search_profile.java:598)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6310)
    at android.view.View$PerformClick.run(View.java:24970)
    at android.os.Handler.handleCallback(Handler.java:794)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6662)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

this is screenshot of gadget tree of designer editor :
upload_2019-5-15_1-49-37.png
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
dont works :c
why you are NOT using the code @mangojack linked?
Your code
Sub lblAction_Click
Dim index As Int = CustomListView1.GetItemFromView(Sender)

Log("lblAction is initialized ? : "&lblAction.IsInitialized)

Dim pnl As B4XView = CustomListView1.GetPanel(0)
Log(pnl.GetView(1))
End Sub

The Code linked:
Sub clv1_ItemClick(Index As Int, Value As Object)
Dim pnl As B4XView = clv1.GetPanel(Index)
pnl.GetView(
0).Text = "abc123" 'view(0) = 1st label on panel.. refer order in Designer ViewTree for Item/Row layout
'...........


In fact you are using the label click event, not the clv itemclick event.

to get the label in the labelclick event you can use
B4X:
Sub lblAction_Click
    dim lblAction as label = sender
    ' work with label
end sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Your code should be ..

B4X:
Sub lblAction_Click
    Dim index As Int = CustomListView1.GetItemFromView(Sender)
    
    Log("lblAction is initialized ? : "&lblAction.IsInitialized)
    
    Dim pnl As B4XView = CustomListView1.GetPanel(index)
    Log(pnl.GetView(1).Text    ' Label_status is second label / view on panel layout ??
 
Upvote 0
Top