CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

zeuspower

Member
Licensed User
Longtime User
Δύναμη Διός, κάπου στον κώδικα σου έχεις δηλώσει μάλλον dim p as phone. Άλλαξε το dim p as panel σε κάποιο άλλον όνομα π.χ. p2.

What a surprise,speaking Greek in here :icon_clap:

Φιλε μου,σωστα,το ειχα δηλωσει παραπανω ...τι κολλημα :signOops:

Αλεξανδρεια ... πως παει εκει ?:)
 
Last edited:

HDBarodi

Member
Licensed User
Longtime User
Dear Erel,

Thanks for your advice.
Unfortunately I am unable to try the example in the first post, and I got an error message:
Error description: Unknown type: reflector
When I go to reference libraries, I found Core (version 2.26) and String Utils (version 1.02) are checked.
So, would you please help me about that?

Best regards
H D Barodi
 

IanMc

Well-Known Member
Licensed User
Longtime User
Tortuous Tangles

Advantages of CustomListView:•Each item is made of a Panel that can hold any views.

Is it possible to design each panel in the designer?
I can't immediately see any way of loading a layout into the CustomListView.

It's just that adjusting positions of views on each panel in code is slow and tortuous :) a bit to the left, compile, nope, down a bit, compile, nope a bit to the right, compile nope ......
 

zeuspower

Member
Licensed User
Longtime User
Is it possible to design each panel in the designer?
I can't immediately see any way of loading a layout into the CustomListView.

It's just that adjusting positions of views on each panel in code is slow and tortuous :) a bit to the left, compile, nope, down a bit, compile, nope a bit to the right, compile nope ......

agree...
 

HDBarodi

Member
Licensed User
Longtime User
Dear All,
First I should thank Erel for this useful tool (really nice).
I make small modification for AddTextItem to make it like AddTwoLines in ListView and it works fine, but when I add a huge number of items (in my test it is 1827 * 2 = 3654) the program crash on some point and stop suddenly.
I tried to add try-catch either in my program or in CustomListView>InsertAt, but it is not work.
Any suggestion to solve this issue please?

Best regards,
H D Barodi
 

HDBarodi

Member
Licensed User
Longtime User
By the way, this is my modifications,
In Class_Globals, I Add:
B4X:
Public DefaultTextSize2 As Int
Public DefaultTextColor2 As Int

and in Initialize I add:
B4X:
DefaultTextColor2 = Colors.Gray
DefaultTextSize2 = 16

and then I add two Subs:
B4X:
Public Sub AddTextItem2(Text1 As String, Text2 As String, Value As Object)
   InsertAtTextItem2(items.Size, Text1, Text2, Value)
End Sub

Public Sub InsertAtTextItem2(Index As Int, Text1 As String, Text2 As String, Value As Object)
   Dim pnl As Panel
   pnl.Initialize("")
   Dim lbl1 As Label
   lbl1.Initialize("")
   lbl1.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
   lbl1.Text = Text1
   lbl1.TextSize = DefaultTextSize
   lbl1.TextColor = DefaultTextColor
   
   Dim lbl2 As Label
   lbl2.Initialize("")
   lbl2.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
   lbl2.Text = Text2
   lbl2.TextSize = DefaultTextSize2
   lbl2.TextColor = DefaultTextColor2
   
   pnl.Color = DefaultTextBackgroundColor
   Dim minHeight As Int
   pnl.AddView(lbl1, 5dip, 2dip, sv.Width - 5dip, 20dip)
   minHeight = su.MeasureMultilineTextHeight(lbl1, Text1)
   lbl1.Height = minHeight
   pnl.AddView(lbl2, 5dip, minHeight + 2dip, sv.Width - 5dip, 20dip)
   minHeight = su.MeasureMultilineTextHeight(lbl2, Text2)
   lbl2.Height = minHeight
   
   InsertAt(Index, pnl, lbl1.Height + lbl2.Height + 2dip, Value)
End Sub
 

Attachments

  • CustomListView.bas
    7.3 KB · Views: 317
Last edited:

Cothek

Member
Licensed User
Longtime User
Just started using B4A here and am wondering how I can use 2 buttons in the same panel? When I call Button_Click I can't distinguish between the two.

Edit: I figured it out.
I initialized the buttons with their own event names and then made sub button1_click and sub button2_click.
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
This is a wonderful class, but I am trying to figure out a solution for the Click event not being raised while refreshing text items at an 50-100 ms intervals. Even at 1 item the lag will occur. Listview is able to handle this without a problem. Is there a way to handle this situation. Add a timer and clear all items and add text item at an 50-100ms interval and see if you can raise the click event. In my case, it will not.
 

Scantech

Well-Known Member
Licensed User
Longtime User
Here you go. If you find a solution, will you be able to update your class? Thank you Erel.
 

Attachments

  • CustomListView.zip
    16.3 KB · Views: 367

Erel

B4X founder
Staff member
Licensed User
Longtime User
The panels do not generate the click event when they are replaced so quickly.
You can change the Panel_Click sub to:
B4X:
Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
   If Action <> 0 Then '0 => Activity.ACTION_DOWN
      If SubExists(CallBack, EventName & "_ItemClick") Then
         Dim v As View
         v = Sender
         CallSub3(CallBack, EventName & "_ItemClick", v.Tag, items.Get(v.Tag))
      End If
   End If
End Sub
This will work better.

You can also change the items text instead of clearing the list and creating new views.
 

xor83

Member
Licensed User
Longtime User
B4X:
[quote="Erel, post: 146278"]Yes. Create a panel and call Panel.LoadLayout.[/QUOTE]

Tried this and loaded layout under CreateListItem sub 
Ex.
[CODE]Dim p As Panel   
p.Initialize("")
p.LoadLayout("li") <<---Panel(listpnl) contains some labels and check boxes

And generated long click from layout designer
Ex.
B4X:
Sub listpnl_LongClick
   Dim index As Int
   index = clv2.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clv2.GetPanel(index)
   
   Dim lbl As Label
   Dim chk As CheckBox
   lbl = pnl.GetView(0)  <<--------------- Error (Object Should first be initialized(View))
   chk = pnl.GetView(2)
   lbl.Text = "Clicked!"
   Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
   
End Sub

Long click raise the event but this line gives me error
lbl = pnl.GetView(0)

what I am doing wrong?:sign0163:
 
Last edited:
Status
Not open for further replies.
Top