Android Question CustomView List Properties

RayGlynn

Member
Licensed User
Longtime User
Hi, Apologies if this has been answered before but; Using a Customview List with several text panels on each row, is there a way to know which column is clicked in the list?
 

Haris Hafeez

Active Member
Licensed User
Longtime User
When you are populating your CustomListView with panels (each representing the row I imagine), you should use the tag property of the view whose click event you intend to handle. Then in the event handler, you should check the tag property. Usually, you'd like to store some sort of key in the tag property which you can later use to retrieve the entire record later on in the event handler.
 
Upvote 0

RayGlynn

Member
Licensed User
Longtime User
Hi Haris,
Thank you for your quick reply. I had thought of using Tag to identify the column but I wasnt sure how to reference it later when the row is clicked. Apologies again if this is basic stuff.

I can identify the column this way:

Dim Cost As Label
Cost.Initialize("")
Cost.Tag = "Cost"

p.AddView(Cost, 305dip, 2dip, 65dip, Height - 4dip) 'Item Cost

But in the event handler:

Sub clv3_ItemClick (Index As Int, Value As Object)

Dim pnl As Panel = clv3.GetPanel(Index)

How do I get what the Tag is?

Thanks for any more help
 
Upvote 0

RayGlynn

Member
Licensed User
Longtime User
Hi Erel,

Im basically calling a subroutine to add each row to the customview list as follows;

For each record in the DB this is run;
B4X:
clv3.Add(CreateBasicListItem(cCursor.GetInt("tblItems.ID"), cCursor.GetString("Item"), cCursor.GetString("Price"), cCursor.GetInt("Pic"), cCursor.GetInt("Qty"), cCursor.GetString("Freq"), cCursor.GetString("Sel"), clv3.AsView.Width, 45dip,clr), 45dip, cCursor.GetInt("tblItems.ID"))
 ' Items


which calls this:

B4X:
Sub CreateBasicListItem(ItemID As Int, CatItem As String, Price As String, Pic As Int, Qty As String, Frq As String, Selct As Int, Width As Int, Height As Int, clr As Int) As Panel
   
    ' ITEMS
   
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    p.Tag = "Itm"
   
    ' CAT / ITEM
   
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = CatItem
    lbl.TextSize = ListFontSize
    lbl.TextColor = Colors.Gray
       
    ' €
   
    Dim Cost As Label
    Cost.Initialize("")
    Cost.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.RIGHT)
    Cost.Text = NumberFormat2(Price,0,2,2,False)
    Cost.TextSize = ListFontSize
    Cost.TextColor = Colors.Gray
    Cost.Tag = "Cost"
   
    ' Camera
   
    Dim im As ImageView
    im.Initialize("")
    If Pic = 1 Then
        im.Bitmap = LoadBitmapSample(File.DirAssets,"camera.jpg",18,14)
    End If

    ' Qty
   
    Dim Qnty As Label
    Qnty.Initialize("")
    Qnty.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.CENTER)
    Qnty.Text = Qty
    Qnty.TextSize = ListFontSize
    Qnty.TextColor = Colors.Gray
    Qnty.Tag = "Qnty"

    ' FR
   
    Dim Freq As Label
    Freq.Initialize("")
    Freq.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    Freq.Text = mapFreq.Get(Frq)
    Freq.TextSize = ListFontSize
    Freq.TextColor = Colors.Gray
    Freq.Tag = "Freq"

    ' Tick   

    Dim Sel As CheckBox
    Sel.Initialize("sel")
    Sel.Gravity = Bit.Or(Gravity.NO_GRAVITY, Gravity.LEFT)

'    Sel.Tag = "1"
'    If Sel.Tag = 1 Then ..... else
'
    Dim Btmp As Bitmap
    Btmp = LoadBitmap(File.DirAssets, "TickBox_star_gray.png")
    Sel.SetBackgroundImage(Btmp)

    Sel.TextSize = 6
    Sel.TextColor = Colors.Black
'    Sel.Color = clr
    Sel.Tag = ItemID
'    Log (Sel.Tag)

    If Selct = 0 Then
        Sel.Checked = False   
    Else
        Sel.Checked = True
'        Sel.SetBackgroundImage(BtmpYes)
    End If


    p.AddView(lbl, 5dip, 2dip, 305dip, Height - 4dip) 'cat/Item
    p.AddView(Cost, 305dip, 2dip, 65dip, Height - 4dip) 'Item Cost
    p.AddView(im,370dip,2dip,75dip,Height - 4dip)' image
    p.AddView(Qnty,435dip,2dip,50dip,Height - 4dip)' Quantity
    p.AddView(Freq,490dip,2dip,50dip,Height - 4dip)' Frequency
    p.AddView(Sel,550dip,2dip,50dip,Height - 4dip)' Select
   
    SetTextColorForRow(p,Sel, Colors.Black,Colors.gray) ' set the text color

    Return p
   
End Sub


So when I click on a row on clv3 I can see the detail of the row on another panel
Thats working fine.

But I just want to know which column I've clicked so I can set focus to that particular item on the detail panel.

I've set a tag on each label as Haris suggested

But its how to use the tag in the ShowItemDetail() routine below:

B4X:
Sub ShowItemDetail(xID As String) As Boolean
   
    txtItem.Text = ""
    txtDesc.Text = ""
    txtCost.Text = ""
    txtQty.Text = ""
    PointToSpinnerItem(spnFreq,"01")
    pnlPhoto.Tag = 0
    imgPhoto.SetBackgroundImage(Null)
    imgPhoto.Color = Colors.white
   
    cCursor=Starter.SQL1.ExecQuery("SELECT * FROM (tblCategory INNER JOIN tblItems ON tblCategory.ID = tblItems.CatID) WHERE tblItems.ID  = " & xID)
    If cCursor.RowCount > 0 Then
        cCursor.Position = 0
       
        PointToSpinnerItem(spnCat,cCursor.GetString("Category"))
        ' Cat   
       
        txtItem.Text = cCursor.GetString("Item")
        ' Item

        txtDesc.Text = cCursor.GetString("Description")
        ' Item

        txtCost.Text = cCursor.GetString("Price")
        ' Cost
       
        txtQty.Text = cCursor.GetString("Qty")
        ' Qty
       
        imgCamera.Tag = cCursor.GetInt("Pic")
       
        Dim sFrq As String = mapFreq.get(cCursor.GetString("Freq"))
        PointToSpinnerItem(spnFreq,sFrq)
        ' Freq
       
        If imgCamera.Tag = 1 Then
        ' Pic
           
            Dim sFile As String = xID & "_pic.jpg"
       
            If File.Exists(File.DirDefaultExternal, sFile) Then

                Dim RSIE As RSImageEffects
                  Dim rotate As Int = rotateBy(File.DirDefaultExternal, sFile)  
                  Dim tmpBitmap As Bitmap 
         
                Dim iH As Int = imgPhoto.Height
                Dim iW As Int = imgPhoto.width
               
                tmpBitmap = LoadBitmapSample(File.DirDefaultExternal, sFile,iW,iH)  
                 
                imgPhoto.Gravity = Gravity.NO_GRAVITY
                  imgPhoto.Bitmap = RSIE.rotate(tmpBitmap, rotate)   
           
            End If
           
            imgCamera.Bitmap = LoadBitmap(File.DirAssets,"camera.jpg")
            imgDelete.Visible = True
            pnlPhoto.Tag = xID

        End If

        Return True

    End If
   
End Sub

hope code isnt too confusing.

Thanks for any help
Ray
 
Upvote 0
Top