Android Question ListView event click

HarryPottier

Member
Licensed User
Hello community
Attached a small ListView
With (ListView1_ItemLongClick) I can delete individual entries
However, what I am missing is the effect of highlighting, or the event on a click
So a short flash, brighten up.
Could somebody give a guy or even adjust the sample program

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: B4A Exemple
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals

    Type tListItem(Eintrag1 As String, Eintrag2 As String)
    Dim ListItems As List
    Dim ListView1 As ListView
    Dim GtrX(99) As String
End Sub


Sub Activity_Resume
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    ListView1.Initialize("ListView1")
    Activity.AddView(ListView1, 0, 20, 100%X, 88%Y)

    ListItems.Initialize
    ListView1.SingleLineLayout.Label.Color = Colors.White
    ListView1.SingleLineLayout.ItemHeight = 100
    ListView1.SingleLineLayout.Label.TextSize = 16
    ListView1.SingleLineLayout.Label.Typeface = Typeface.MONOSPACE
    ListView1.SingleLineLayout.Label.TextColor = Colors.Black
    ' ListView1.SingleLineLayout.Label.Typeface = Typeface.DEFAULT_BOLD
    
    LoadGTR
    
    Dim i As Int
    For i = 1 To 15
        ListView1.AddSingleLine(" " & GtrX(i))
    Next
    
    For Counter = 0 To ListItems.Size - 1
        Dim ListItem As tListItem
        ListItem = ListItems.Get(Counter)
        ListView1.AddSingleLine(ListItem.Eintrag1)
    Next

End Sub


Sub ListView1_ItemClick (Position As Int, Value As Object)

    Dim GetrIndex As Int
    Dim GetrText As String
    GetrIndex = Position
    GetrText = Value
End Sub

Sub ListView1_ItemLongClick (Position As Int, Value As Object)

    Dim GetrIndex As Int
    Dim GetrText As String
    GetrIndex = Position
    GetrText = Value
    ListView1.RemoveAt(GetrIndex)
    
End Sub

Sub LoadGTR
    
GtrX(1) = "Cola 0,2l                  2.20"
GtrX(2) = "Fanta 0,2l                 2.20"
GtrX(3) = "Sprite 0,2l                2.30"
GtrX(4) = "Pils  0,3                  2.50"
GtrX(5) = "Export  0,3                2.90"
GtrX(6) = "Desperados                 3.50"
GtrX(7) = "Riesling  Schorle  0,5     3.20"
GtrX(8) = "Weisßherbst Schorle 0,5    3.20"
GtrX(9) = "Burgunder  0,2             2.80"
GtrX(10) = "Café                       1.80"
GtrX(11) = "Espresso                   1.80"
GtrX(12) = "Milchcafé                  2.50"
GtrX(13) = "Latte Macchiato            2.50"
GtrX(14) = "Cappuccino                 2.50"
GtrX(15) = "Heiße Schokolade           2.50"
    
End Sub
 

Revisable5987

Member
Licensed User
https://www.b4x.com/android/forum/t...-cross-platform-customlistview.84501/#content
Highly recommend looking here

You'll find that it is vastly more customisable, the example I've shown does not do justice but you'll get the basic principle.
You can create your own layout in designer to get the exact look you require. Check out the link to learn more

Also have a look at the attached project which shows your example changed to a custom list view.
 

Attachments

  • example.zip
    9.6 KB · Views: 234
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Its probably been suggested before but .. It would be simpler to change to xCustomListView

Many times this question has been asked ..

EDIT : strangely @kgcarpenter post was not present at time of reply ... ?
 
Last edited:
Upvote 0

HarryPottier

Member
Licensed User
Thanks Carpenter an Jack, the CustomListView works well
However, there are several settings that I can't get right.
I want to change the size of the object.
I want to change the ACTION_DOWN to Press
I want to change the font to MonoSpace at runtime.


B4X:
Activity.AddView(CLV, 0, 20, 100%x, 80%y)     ' Do not function
CLV.AsView.TOUCH_ACTION_DOWN = True         ' Do not function
CLV.AsView.Font.ToNativeFont.MONOSPACE         ' Do not function
CLV.AsView.Color = Colors.White             ' Functional
 
Upvote 0

Revisable5987

Member
Licensed User
EDIT : strangely @kgcarpenter post was not here at time of replying ?
Still new to the forum so posts aren't shown straight away :)

Thanks Carpenter an Jack, the CustomListView works well
However, there are several settings that I can't get right.
I want to change the size of the object.
I want to change the ACTION_DOWN to Press
I want to change the font to MonoSpace at runtime.


B4X:
Activity.AddView(CLV, 0, 20, 100%x, 80%y)     ' Do not function
CLV.AsView.TOUCH_ACTION_DOWN = True         ' Do not function
CLV.AsView.Font.ToNativeFont.MONOSPACE         ' Do not function
CLV.AsView.Color = Colors.White             ' Functional

If you're looking to change the size or color of items in the list then I would use 'clv.add' and create your own layout in designer.
I don't know what you're trying to achieve with 'TOUCH_ACTION_DOWN?
As I said in my previous post I recommend reading through the xCustomListView tutorial.
It's very informative and the xCLV is very customisable
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I'm not making much progress with my English.
I am German with French knowledge
You may be better off posting in the German and/or French forum. There are some excellent forum members that speak those two languages. You are almost guarantied an answer.
 
Upvote 0
Top