Android Question How to get items in customlistview?

ViMeAv ICT

Member
Licensed User
Longtime User
I use the customlistview to scroll to images with on every image a textlabel. (b4xview)
When i click on a image i need to change the text of that textlabel.

I go to another screen, change text and go back, without complete refresh of the
whole clv. I want to update just that corresponding textlabel on that particular image.

How can i do this? I use .add function which add the loaded layout to the clv as a b4xview.
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
I don't think you are supplying enough information for a member to help. You need to put down what code you are trying and a copy of your items layout to see the hierarchy of the views in the items layout.
 
Upvote 0

ViMeAv ICT

Member
Licensed User
Longtime User
For example your own xCLVImageGalleryMahares.
Here you fill a customlistview with items, with a label (lbl1 - lbl4) and a picture (Iv1 - Iv4)
Now I click item3 on third row.
Go to another screen, showing picture in big and lbl3 as description.
Now I want to change description and go back to customlistview,
without completely rebuild, only the lbl3.text must be changed.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
@ViMeAv ICT
The task you want to do it's quite easy, but to better help you it's needed to see your Item Layout to know how to reference the label that you need to modify.
 
Upvote 0

ViMeAv ICT

Member
Licensed User
Longtime User
example:
Sub Globals
    Private Mainlist As CustomListView
end sub

Sub Activity_Create(FirstTime As Boolean)
Dim cursor1 As Cursor

Activity.LoadLayout("Layout1")

cursor1 = Main.SQLDB.ExecQuery("SELECT DISTINCT ARTGROEP.GRPNR, ARTGROEP.GRPOMS FROM ARTGROEP ORDER BY ID ASC;")
If (cursor1.RowCount > 0) Then
    cursor1.Position = 0
    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = i
        MainList.Add(MainItem(cursor1.GetString("GRPOMS").Trim),cursor1.GetString("GRPNR").trim)
    Next
End If
cursor1.Close

End Sub

Sub MainItem (txt As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("Panel")
    Dim  TargetDir As String

    If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
    
    p.SetLayoutAnimated(0, 0, 0,MainList.AsView.Width,MainList.AsView.Height/3)
    p.LoadLayout("item")
    
    Label0.Color = Colors.White  ''Transparent
    Label0.TextColor = Colors.black
    Label0.TextSize = 18
    Label0.Top = Imageview0.Height - 5%y
    Label0.Left = 2%x
    Label0.Width = 15%x
    Label0.Height = 4%y
    
    If (File.Exists(TargetDir & "/PICTURES/GROEP",txt & ".JPG") = True) Then
        Imageview0.Bitmap = xui.LoadBitmapResize(TargetDir & "/PICTURES/GROEP", txt & ".JPG",Imageview0.Width,Imageview0.Height,True)
    End If
    Label0.Text = txt
    
    Return p
End Sub

Sub MainList_ItemClick (Index As Int, Value As Object)
'' here i go to another screen.
'' showing picture and changing text
'' after that going back to customlist, not rebuilding but only
'' corresponding label0.text has to be changed.
end sub
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    Private Mainlist As CustomListView
    Public TargetLabel as Label
end sub
B4X:
Sub MainList_ItemClick (Index As Int, Value As Object)
   Dim p as Panel = MainList.Getpanel(index)
   TargetLabel = p.GetView(0) 'This can be wrong without knowing you View Tree of the Layout
   'Open your modification page and assign the new text to TargetLabel.Text
end sub
Without knowing your project I can't do more than this.
 
Upvote 0

ViMeAv ICT

Member
Licensed User
Longtime User
View tree consist of Imageview0 and Label0.
Why should your TargetLabel directs to Label0 and not to Imageview0
Or is every control a Getview.
So when I have a label1, label2, label3 and ImageView0. (corresponding to the tree)
The getview(0) is label1, getview(1) is label2, getview(2) is label3, getview(3) is Imageview0 ?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
If your View Tree it's like this then
Label >>> GetView(0)
ImageView >>> GetView(1)
If you have only this two views than it's just a matter of a 0 or a 1 in the GetView command. ;)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
View tree consist of Imageview0 and Label0.
Why should your TargetLabel directs to Label0 and not to Imageview0
Or is every control a Getview.
So when I have a label1, label2, label3 and ImageView0. (corresponding to the tree)
The getview(0) is label1, getview(1) is label2, getview(2) is label3, getview(3) is Imageview0 ?
Correct.
But...... If some Views are contained into an additional Panel on the layout then it become a bit more complex.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you attached your items layout file like I asked you in the 2nd post, you could have saved yourself a lot of unnecessary posts back and forth and Sagenut could have helped you right away.
 
Upvote 0
Top