Android Question Custom Listview itemclicked help?

Discussion in 'Android Questions' started by Mohamed Akbarally, May 17, 2015.

  1. Mohamed Akbarally

    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?
     
  2. klaus

    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 ?
     
    Peter Simpson and RandomCoder like this.
  3. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    Code:
    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%y40%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%x70%y'view #2
        p.AddView(imgv2 ,-12%x, -15%y , 60%x70%y'view #2
        p.AddView(lbl ,-1%x3%y , 40%x30%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
     
  4. RandomCoder

    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".
     
  5. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    ya i tried that but is there a way to pass a value or get the specific item clicked like that?
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Yes, I use the Tag for that purpose which it doesn't look like you're already using and so should be ok.
     
    Mohamed Akbarally likes this.
  7. klaus

    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:
    Code:
    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 ?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice