B4i Library [class] CustomListView

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Just updated the library and trying to guess how I can disable the click event.

I don't wanna that row blink when the row was clicked. Imagine a chat... I just need to show the historic messages but won't expose any actions on it. Does this make sense?

Thanks.
Daniel
 

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Never mind... Just changed the class to have

B4X:
    Private HighlightColor As Int = Colors.Transparent
 

sdesan

Member
Licensed User
Longtime User
I need, as made in b4a, of customize first and second line text size or line height of list view, pass a value to retrieve on click event and then open a file. Starting from b4a code

B4X:
'B4A code
Sub Globals
   Dim lstTracce As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  lstTracce.TwoLinesLayout.Label.TextSize = 14
  lstTracce.TwoLinesLayout.Label.Height = 60dip
  lstTracce.TwoLinesLayout.Label.Top=0
  lstTracce.TwoLinesLayout.SecondLabel.Top = lstTracce.TwoLinesLayout.Label.Height
  lstTracce.TwoLinesLayout.SecondLabel.TextSize = 12
  lstTracce.TwoLinesLayout.SecondLabel.Height = 40dip
  lstTracce.TwoLinesLayout.ItemHeight = lstTracce.TwoLinesLayout.Label.Height + lstTracce.TwoLinesLayout.SecondLabel.Height
  i = 0
  Do While i <7
    i = i+1
    lstTracce.AddTwoLines2(i,10+i,50+i)
  Loop
  lstTracce.SetSelection(0)
End Sub

Sub LstTracce_ItemClick (Position As Int, Value As Object)
   Dim selection As String
   Dim i As Intent
   selection ="file_" & Value & ".txt"
   If File.Exists(File.DirRootExternal, "/scabr/" & selection ) = False Then
       File.Copy(File.DirAssets, selection, File.DirRootExternal, "/scabr/" & selection )
   End If
   i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirRootExternal, "/scabr/" & selection ))
   i.SetType("text/xml")
  Try
   StartActivity(i)
  Catch
   ToastMessageShow("Unable to open file.", True)
  End Try
End Sub

i write this code

B4X:
'b4i code
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Public lstTracce As TableView
End Sub

Sub MyButton_Click
   main1.Initialize("main1")
   main1.Title = "My app"
   main1.RootPanel.LoadLayout("main")
   main1.RootPanel.AddView(lstTracce,0, 120, 100%x, 50%y)
   NavControl.ShowPage(main1)
   For i= 0 to 6
         lstTracce.AddTwoLines(i,10+i)
    Next
    lstTracce.ReloadAll
End Sub

Sub LstTracce_SelectedChanged (SectionIndex As Int, Cell As TableCell)
   Dim selection As String
   selection ="file_" & Cell.Text.ToString & ".txt"
   Try
     Msgbox(selection ," File to open ")
  'StartActivity(i)
  Catch
    Msgbox("Unable to open file.", "Error")
  End Try
End Sub

But in this way i need to name txt file (or fill TableView) with same name of file, but it will be more efficent to pass a value like in AddTwoLines2 on b4a
Last problem: TableView is not word-wrapp capable so i'm looking to this custom list view class but i have not find a good way.
Any help will be appreciated
 
Last edited:

jazzzzzzz

Active Member
Licensed User
Longtime User
how to remove all item in customlistview

B4X:
For j=0 To clv1.GetSize-1
        clv1.RemoveAt(j)
Next
this gives out of bound error at clv module
 

ilan

Expert
Licensed User
Longtime User
how to remove all item in customlistview

B4X:
For j=0 To clv1.GetSize-1
        clv1.RemoveAt(j)
Next
this gives out of bound error at clv module

the reason for that error is.

you are going in a loop from 0 to x and delete inside the loop items what will also change the size of the list (x) so in about the half way the loop will not be able to get the next items since the size is now different.

example:

for i = 0 to list1.size -1 (list1.size = 10)
list1.removeat(i)
next

when i = 0 then item 0 in the list will be deleted what means list1.size is now only 9 and not 10 like before
when i = 1 then item 1 will be deleted and list size is now 8 ...

but the loop will still try to get until i = 10 because this is what we asked him to do!

so you better try

clv1.Clear
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Any way to change the selection color of clv items? now it grey i want it to be maroon
 

ilan

Expert
Licensed User
Longtime User
Any way to change the selection color of clv items? now it grey i want it to be maroon

yes, that should be possible, look in the class for a panel click event and see if it is changing the backcolor to gray and change it the one u want.
 

ilan

Expert
Licensed User
Longtime User
this is the sub

B4X:
Private Sub Panel_LongClick
   Dim p As Panel = Sender
   p.GetView(0).Color = HighlightColor
   p.GetView(0).SetColorAnimated(700, Colors.Transparent)
   CallSub3(CallBack, EventName & "_ItemLongClick", p.Tag, items.Get(p.Tag))
End Sub

Private Sub Panel_Click
    Dim p As Panel = Sender
    p.GetView(0).Color = HighlightColor
    p.GetView(0).SetColorAnimated(700, Colors.Transparent)
    CallSub3(CallBack, EventName & "_ItemClick", p.Tag, items.Get(p.Tag))
End Sub

as u can see @Erel declared the selection color as a global variable to make our life easier

so just change in Sub Class_Globals

B4X:
Private HighlightColor As Int = Colors.LightGray

to what ever u want
 

tpakis

Active Member
Licensed User
Longtime User
How can change clv visibility, height,width,left,top with code and not from the designer, obviously after the layout was loaded?
 

LucaMs

Expert
Licensed User
Longtime User
CustomView1.AsView returns the base panel which is the container of the view, so you can use it: CustomView1.AsView.Visible = False.

If you change its width and height, however, you must do so before you load the Items, otherwise they will not be adapted.
 

jahswant

Well-Known Member
Licensed User
Longtime User
Note that you should make sure that there is a live reference to all instances of CustomListView. Otherwise the instance will be released and the events will not be raised.

You can use a global variable to store a live reference.
What's the meaning of this ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…