background color of selected listview line

fotosettore

Member
Licensed User
Longtime User
hi
i'd like to change background color in a listview with addtwolines
it is Yellow when i click ...but i'd like that it remain Yellow ever, even after i remove finger from line (so it simulate the choice)

i know that the right instruction is inside

>>>> ListView1_ItemClick (Position As Int, Value As Object)

>>>> end sub

using "position", but i tried to change background without success.

any idea ?
many thanks
 

enonod

Well-Known Member
Licensed User
Longtime User
I wanted the same indication so I used the first column to place a marker character, which is persistent. Maybe this can be adapted? The part required is in 'X' which changes according to the selected position which uses a global variable 'marker' which holds the position touched then places the character in 'X' at that position. Once placed, redisplay the ListView.
B4X:
Part of ListView display code
...
...
   If lst.Size>0 Then
      For i = 0 To lst.Size-1
         p=lst.Get(i) : x=" " :   s1=p.score : l1=p.level
   
            If i=marker  Then x="*" Else x=" "
               lvCommon.AddTwoLines(x,p.Name&n.substring(p.Name.Length) _
               &s.SubString(s1.length)&s1 _
               &" L"&l1&l.SubString(l1.length) & "C"&p.clrs)
         End If
      Next
   End If
End Sub

Sub lvCommon_ItemClick(Position As Int, Value As Object)
      btn1.enabled=True
      btn1.TextColor=Colors.blue
      marker=Position
                'redisplay list with marker
      'However you called your LV display 

End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
stevel05 .. nice work , that will come in handy

Cheers mj
 
Upvote 0
Top