Spanish [B4A] Generar una lista v0.2, Librerías (CustomListView, CardView, AHSwipeToRefresh)

rscheel

Well-Known Member
Licensed User
Longtime User
Estimados les comparto este pequeño código, que les servirá para generar una lista con datos que quieran mostrar, la lista la pueden personalizar a su gusto, también pueden refrescar la lista, esto lo deben adaptar según su necesidad.

Link librerias.

CustomListView

CardView

AHSwipeToRefresh


Versión de Código: 0.2

Nuevo:
* Al llegar al final de la lista carga nuevos Items o nuevos Registros, Item predeterminados son 10, Esto es lo mas Parecido a RecyclerView que he podido llegar.

* Librería CustomListView v1.75 esta incluida en .bas dentro del ejemplo completo que dejare adjunto.

B4X:
Sub Process_Globals
    Dim tm As Timer
    Dim n_item As Long
    Dim min_item As Long
    Dim ultimo_item As Long
End Sub

Sub Globals
    Private CustomList As CustomListView 'I believe in the designer LayoutMain
    Private CardView As CardView 'I believe in the designer LayoutCellItem
    Dim STR As AHSwipeToRefreshMulti  'I believe in the designer LayoutMain
    Private PanelListView As Panel 'I believe in the designer LayoutMain
    Dim RV As RippleView
    Private LabelVermas As Label 'I believe in the designer LayoutMscard
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("LayoutMain")
    PanelListView.RemoveView
    STR.AddView(PanelListView)
    'STR.SetColorScheme2(Array As Int (Colors.Red, Colors.Blue, Colors.Green, Colors.Cyan, Colors.Magenta, Colors.Yellow))
    STR.SetColorScheme2(Array As Int (Colors.rgb(192,202,51)))
    ProgressDialogShow2("Cargando, espere...", False)
    n_item = 10
    min_item = 1
    ultimo_item = 1
    Dim l As List
    l.Initialize
    l.Add(CustomList.AsView)
    STR.SwipeableChilden = l
    CargaLista
End Sub

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
    Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("LayoutCellItem")
    CardView.LoadLayout("LayoutMscard")
    RV.Initialize(LabelVermas, Colors.LightGray, 200, True)
    p.RemoveView
    Return p
End Sub

Sub CargaLista
    Sleep(500)
    For i = min_item To n_item
        CustomList.Add(CreateListItem($"Item #${i}"$, CustomList.AsView.Width, 270dip), 282dip, $"Item #${i}"$)
    Next
    ProgressDialogHide
    min_item = n_item
End Sub

Sub CustomList_ReachEnd
    Log("reach end")
    ultimo_item = 2
    STR.Refreshing = True
    STR_Refresh
End Sub

Sub STR_Refresh
    Log("Refresh started")
    'Start the timer. Normally you will start your asynchronous job here
    tm.Initialize("Timer", 2000)
    tm.Enabled = True
    'Disable the STR object so we can not start a new refresh process
    STR.Enabled = True
End Sub

'The timer tick simulates the end of the refreshing process
Sub Timer_Tick
    Log("Refresh stopped")
   
    'Stop Timer and refresh the listview data
    tm.Enabled = False
    If ultimo_item == 2 Then 'Agrega nuevos item
        n_item = n_item + 10
        min_item = min_item + 1
        Log("Item a Agregar: " & n_item)
    Else 'Recarga Lista
        CustomList.Clear
        min_item = 1   
    End If
    ultimo_item = 1
    CargaLista

    'Stop the spinning disc and enable the STR object again.
    STR.Refreshing = False
    STR.Enabled = True
End Sub

Sub LabelVermas_Click
    Dim index As Int = CustomList.GetItemFromView(Sender)
    ToastMessageShow("Checked items: " & CustomList.GetValue(index), False)
End Sub

Sub CardView_Click
'    Dim index As Int = CustomList.GetItemFromView(Sender)
'    ToastMessageShow("Checked items: " & CustomList.GetValue(index), False)
End Sub

Con el aporte de todos podemos llegar a algo mejor, dejen sus comentarios y aportes.

Saludos.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…