Android Question Custom List View - horizontal and vertical scrolling possible?

rlocke

Member
Hi all,

I'm working on a B4X project (it only needs to work for Android), and I am having trouble getting horizontal and vertical scrolling to work with a Custom List View.

For vertical-only scrolling, this code works perfectly (and I'm able to click on a row, and pass its IdentityNo to the next screen):

Vertical scrolling (works):
Sub CreateListItem_BAK(IdentityNo As String, Film As String, Genre As String, Year As String, Width As Int, Height As Int, Counter As Int) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("ItemSelectItems")
    
    Label1.Text = IdentityNo
    Label1.TextColor = Colors.Black
    
    Label2.Text = Film
    Label2.TextColor = Colors.Black
    
    Label3.Text = Genre
    Label4.Text = Year
    

    If Film = "Enchanted" Then
        p.Color = Colors.Red
    Else
        If Counter Mod 2 = 0 Then
            p.Color = Colors.White
        Else
            p.Color = Colors.LightGray
        End If
    End If
    
    
    Return p
End Sub

Sub ItemListView_ItemClick(Index As Int, Value As Object)
    ItemListView.AsView.BringToFront
    
    Main.gSelectedItemID = Value
    Log("Selected item's IdentityNo: " & Main.gSelectedItemID)
    
    B4XPages.ShowPage("Page Test")
End Sub

This is how it looks:
01.jpg


I would like to have vertical and horizontal scrolling, so I tried this:

Horizontal and Vertical scrolling:
Sub CreateListItem(IdentityNo As String, Film As String, Genre As String, Year As String, Width As Int, Height As Int, Counter As Int) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    
    Dim MyView As HorizontalScrollView
    MyView.Initialize(Width, "myview")
    
    MyView.Panel.LoadLayout("ItemSelectItems")
    MyView.Panel.Width = 300%x
    
    Label1.Text = IdentityNo
    Label1.TextColor = Colors.Black
    
    Label2.Text = Film
    Label2.TextColor = Colors.Black
    
    Label3.Text = Genre
    Label4.Text = Year
    
    
    p.AddView(MyView, 0, 0, Width, Height)

    If Film = "Enchanted" Then
        p.Color = Colors.Red
    Else
        If Counter Mod 2 = 0 Then
            p.Color = Colors.White
        Else
            p.Color = Colors.LightGray
        End If
    End If
    
    
    Return p
End Sub

Two issues with this code:
  1. Vertical and horizontal scrolling works, but each row has its own horizontal scrollbar, and I would like just one horizontal scrollbar
  2. Clicking on each row doesn't trigger any events, so I can't pass the row's IdentityNo to the next screen
02.jpg


My questions:
  1. Is is possible to achieve horizontal and vertical scrolling (with a click event) using Custom List View? If so, can someone please help?
  2. Or do I need to use the Flexible Table class to achieve this? Sorting and fixed headers are not important, nor is iOS compatibility.
And here's a link to the project's code:

https://1drv.ms/u/s!AkXBU47dmlTrg-4plS-kRVlEXiF45w?e=7xEhP5

Thank you!
 

klaus

Expert
Licensed User
Longtime User
You could do it with ScrollView2D.
As your rows are simple, it is not difficult.
You need to define an AddRow routine similar to what you do for the CutomListView.
The Flexible Table Class uses ScrollView2D for the bidirectional scrolling.
 
Upvote 1

Mahares

Expert
Licensed User
Longtime User
  1. Is is possible to achieve horizontal and vertical scrolling (with a click event) using Custom List View? If so, can someone please help?
  2. Or do I need to use the Flexible Table class to achieve this? Sorting and fixed headers are not important, nor is iOS compatibility.
Only vertical scrolling with xClv. Flexible Table is an option. But, the one I would use for your project after taking a look at it where you want the benefit of a search feature is B4XTable. It has horizontal scrolling and is page based which means you can go from page to page, seeing from 10 to 25 records at a time depending on row height. But with the search feature you do not need a lot of vertical scrolling. Whatever decision you make, there is a lot of help from members here. I know I and others can help with B4XTable, klaus is a powerhouse with Flexible Table. Here is a snapshot of some of the columns you have with B4Xtable, the other columns are outside the screenshot.
 

Attachments

  • movies.png
    movies.png
    36.9 KB · Views: 290
Upvote 1

rlocke

Member
Hi @klaus and @Mahares - thank you for pointing me in the right direction.

I was able to get it working using B4XTable; at first I wasn't sure if the paging would work well for the data (I still wish there was a way to display all rows on a single screen, without paging), but it was super easy to implement.

Thanks!
 

Attachments

  • table.jpg
    table.jpg
    154.1 KB · Views: 258
Upvote 0
Top