Scrollview panel click

sultan87

Active Member
Licensed User
Longtime User
Hello j' created a scrollview as follows how to know about which item (panel1) j' have click
Best regards

Sub FillScrollView
Dim Bitmap1 As Bitmap
Dim Panel0 As Panel
Dim PanelTop, PanelHeight, lblNomTop As Int

Bitmap1.Initialize(File.DirAssets,"bouteille.jpg")
PanelTop=0
Panel0=scvListVins.Panel
Panel0.Color=Colors.Transparent

curseur = SQL.ExecQuery("SELECT Nom, Année, Bouteilles, Couleur FROM ListeVins")

For i = 0 To Curseur.RowCount - 1
Curseur.Position = i

Dim Panel1, Panel2 As Panel
Dim ImageView1 As ImageView

Panel1.Initialize("")
PanelHeight=74dip
lblNomTop=40dip

Panel0.AddView(Panel1,0,PanelTop,scvListVins.Width,PanelHeight)

Panel2.Initialize("")
Panel1.AddView(Panel2,5dip,10dip,70dip,5dip)
Select Case curseur.GetString("Couleur")
Case "Blanc"
Panel2.Color=Colors.White
Case "Rouge"
Panel2.Color=Colors.Red
Case "Rosé"
Panel2.Color=Colors.Magenta
Case Else
Panel2.Color=Colors.Cyan
End Select

Dim lblAnnéeNom, lblBouteilles As Label
lblAnnéeNom.Initialize("")
Panel1.AddView(lblAnnéeNom,80dip,5dip,240dip,30dip)
lblAnnéeNom.Color=Colors.Black
lblAnnéeNom.Tag="lblAnnéeNom"
lblAnnéeNom.Text = curseur.GetString("Année") & ", " & curseur.GetString("Nom")

ImageView1.Initialize("")
Panel1.AddView(ImageView1,5dip,20dip,65dip,65dip)
ImageView1.Bitmap=Bitmap1

lblBouteilles.Initialize("")
Panel1.AddView(lblBouteilles,80dip,30dip,240dip,30dip)
lblBouteilles.Tag="lblBouteilles"
lblBouteilles.Text = curseur.GetString("Bouteilles") & " bouteille(s)"
lblBouteilles.TextSize=11

PanelTop=PanelTop+PanelHeight+1dip

Next

Curseur.Close

Panel0.Height=PanelTop

End Sub
 

klaus

Expert
Licensed User
Longtime User
Le code ci-dessous devrait fonctionner.
B4X:
Sub FillScrollView
    Dim Bitmap1 As Bitmap
    Dim Panel0 As Panel
    Dim PanelTop, PanelHeight, lblNomTop As Int
    
    Bitmap1.Initialize(File.DirAssets,"bouteille.jpg")
    PanelTop=0
    Panel0=scvListVins.Panel
    Panel0.Color=Colors.Transparent
        
    curseur = SQL.ExecQuery("SELECT Nom, Année, Bouteilles, Couleur FROM ListeVins")
    
    For i = 0 To Curseur.RowCount - 1
        Curseur.Position = i

        Dim Panel1, Panel2 As Panel
        Dim ImageView1 As ImageView
        
        Panel1.Initialize("[COLOR=Red]Ligne[/COLOR]")
        [COLOR=Red]Panel1.Tag = i[/COLOR]
        PanelHeight=74dip
        lblNomTop=40dip

        Panel0.AddView(Panel1,0,PanelTop,scvListVins.Width  ,PanelHeight)
        
        Panel2.Initialize("")
        Panel1.AddView(Panel2,5dip,10dip,70dip,5dip)
        Select Case curseur.GetString("Couleur")
            Case "Blanc"
                Panel2.Color=Colors.White
            Case "Rouge"
                Panel2.Color=Colors.Red
            Case "Rosé"
                Panel2.Color=Colors.Magenta
            Case Else
                Panel2.Color=Colors.Cyan
        End Select
        
        Dim lblAnnéeNom, lblBouteilles As Label
        lblAnnéeNom.Initialize("")
        Panel1.AddView(lblAnnéeNom,80dip,5dip,240dip,30dip  )
        lblAnnéeNom.Color=Colors.Black
        lblAnnéeNom.Tag="lblAnnéeNom"
        lblAnnéeNom.Text = curseur.GetString("Année") & ", " & curseur.GetString("Nom")

        ImageView1.Initialize("")
        Panel1.AddView(ImageView1,5dip,20dip,65dip,65dip)
        ImageView1.Bitmap=Bitmap1

        lblBouteilles.Initialize("")
        Panel1.AddView(lblBouteilles,80dip,30dip,240dip,30  dip)
        lblBouteilles.Tag="lblBouteilles"
        lblBouteilles.Text = curseur.GetString("Bouteilles") & " bouteille(s)"
        lblBouteilles.TextSize=11

        PanelTop=PanelTop+PanelHeight+1dip
        
    Next
    
    Curseur.Close

    Panel0.Height=PanelTop
    
End Sub

[COLOR=Red]Sub Ligne_Click
    Dim pnl As Panel
    pnl = Sender
    Activity.Title = "Ligne sélectionnée = " & pnl.Tag
End Sub[/COLOR]
Attention aux points suivants:
Select curseur.GetString("Couleur") et non Select Case curseur.GetString("Couleur")

Code pas testé !

Meilleures salutations.
 
Upvote 0

sultan87

Active Member
Licensed User
Longtime User
Bonsoir
Merci j'ai testé et ça repond favorablement

Pour le SELECT
Select Case curseur.GetString("Couleur")

cela fonctionne correctement

Cordialement
 
Upvote 0
Top