Android Question Custom Listview itemclicked help?

Mohamed Akbarally

Member
Licensed User
hi, i have downloaded the custom listview library and am using it to display a series of images with labels on it. But when i do this the custom listview clicked is not recognized (cc_ItemClick(Index As Int, Value As Object)), is there another way is which i can get the value of the item clicked?
 

klaus

Expert
Licensed User
You need to show us your code otherwise it's almost impossible to help.
How do you declare and Initialize the CustomListView ?
How do you add the items ?
Do you have a ItemClick event in your code with the generic name you set in the Initialize routine ?
 

Mohamed Akbarally

Member
Licensed User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    cc.Initialize(Me, "cc")
    Activity.LoadLayout("WandM")
    Activity.AddView(cc.AsView, 60%x,8%y, 40%x,80%y)
....
....
...
End Sub
Sub Button7_Click
For i = 1 To 10
    cc.Add(CreateListItem("t"& i & ".png",tshirtprices(i)), 30%y, "t"& i & ".png")
Next
End Sub
Sub CreateListItem(picture As String, price As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.LightGray
    Dim imgv As ImageView
    imgv.Initialize("img")
    imgv.Gravity = Gravity.FILL
    Dim imgv2 As ImageView
    imgv2.Initialize("img2")
    imgv2.Gravity = Gravity.FILL
    imgv2.Bitmap = a
    imgv.Bitmap = LoadBitmapSample(File.DirAssets,picture,40%x,40%y)
    Dim lbl As Label
    lbl.Initialize("lbl")
    lbl.Gravity = Gravity.CENTER
    lbl.TextColor = Colors.Black
    lbl.TextSize = 10dip
    lbl.Text = "$"& price
    p.AddView(imgv ,-12%x, -15%y , 60%x, 70%y) 'view #2
    p.AddView(imgv2 ,-12%x, -15%y , 60%x, 70%y) 'view #2
    p.AddView(lbl ,-1%x, 3%y , 40%x, 30%y)
    Return p
End Sub
Sub cc_ItemClick(Index As Int, Value As Object)
    Dim str As String
    vavl = Value
    Dim dd As Int
    str = File.ReadString(File.DirInternal,"Items.txt")
    If str.Contains(vavl) = False Then
    dd = vavl.SubString2(1,vavl.IndexOf("."))
    If Home.money > tshirtprices(dd) Then
    Dim result As Int
    result = Msgbox2("Confirm Purchase", "Are you sure you want to Purchase this item","Purchase","Cancel",Null,LoadBitmap(File.DirAssets,"shoppingcart.png"))
    If result = DialogResponse.POSITIVE Then
    Home.money = Home.money - tshirtprices(dd)
    File.WriteString(File.DirInternal,"money.txt", Home.money)
    File.WriteString(File.DirInternal,"Item.txt",str & " " & Value)
    File.WriteString(File.DirInternal,"tshirt.txt",Value)
    End If
    Else
    beep.beep
    End If
    Else
    File.WriteString(File.DirInternal,"tshirt.txt",Value)
    'File.WriteString(File.DirInternal,"shoes.txt","hobo_shoes.png")
    End If
   
End Sub
and when i run it the custom list view is not clickable
 

RandomCoder

Well-Known Member
Licensed User
I wasn't aware that there was an ItemClick event. With the CustomListView I have used before I've set events for the items loaded into the list. e.g. in you're example you should have Click events "img_Click", "img2_Click" and "lbl_Click".
 

Mohamed Akbarally

Member
Licensed User
I wasn't aware that there was an ItemClick event. With the CustomListView I have used before I've set events for the items loaded into the list. e.g. in you're example you should have Click events "img_Click", "img2_Click" and "lbl_Click".
ya i tried that but is there a way to pass a value or get the specific item clicked like that?
 

klaus

Expert
Licensed User
The cc_ItemClick event should work.
Are you sure that the cc_ItemClick event is not called ?
You should add a breakpoint in the event routine to see if it is called.
In the returned parameters are :
Index = Item index
Value = Container Panel of the selected item, which is a Panel.
In your code:
B4X:
Sub cc_ItemClick(Index As Int, Value As Object)
    Dim str As String
    vavl = Value
    Dim dd As Int
    str = File.ReadString(File.DirInternal,"Items.txt")
    If str.Contains(vavl) = False Then
What type is vavl ?
It should be a Panel.
It's not a String as you assume.
From this Panel you can get its internal Views.

Do you have a small test project you could post as a zip file, so we could have a look at it ?
 
Top