B4A Library CustomListView - A flexible list based on ScrollView

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 15, 2012.

Thread Status:
Not open for further replies.
  1. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    I did:

    Code:
    Dim pnl As Panel
    pnl = listApk.GetPanel(itemKey)
    Dim b As Button
    b = pnl.GetView(
    1)
    Log("b: " & b.Text)
     
  2. rzv25

    rzv25 Member Licensed User

    I have a silly question about custom listview. I want to have the grid lines (separators) of colour gray. So I set sv.Color =colors.gray in the CustomListVIew class. The problem is that the listview is spread across entire display and if I only have 1 or 2 items in the list, the empty part of the list is displayed gray. And I want it black.
    What properties do I need to set in order to have the grid lines one colour and the listview background another color ?

    Also, another question. Can I add a header to the list ?

    Thank you
     
    Last edited: Feb 19, 2015
  3. Erel

    Erel Administrator Staff Member Licensed User

    There aren't really any separators. There is a small gap between each two items. One possible solution is to create another empty item at the end of the list to fill the entire view.

    Not inside the ScrollView. Only with another view above it.
     
  4. trueboss323

    trueboss323 Active Member Licensed User

    Hey, I got a question. Using this listview, how can I refer to one of the checkboxes? For example, by code, I want to check the checkbox in the 3rd row. How can I do that?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can get any item's panel with GetPanel. Then you need to know the order of views to get the checkbox with Panel.GetView.
     
  6. trueboss323

    trueboss323 Active Member Licensed User

    Could you please provide an example. I tried doing the p.GetView(chk) but wasn't sure what to do next.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Something like:
    Code:
    Dim p As Panel = clv.GetPanel(0'first item
    Dim chk As CheckBox = pnl.GetView(2'assuming that the checkbox is the third item in the layout
     
  8. trueboss323

    trueboss323 Active Member Licensed User

    I get this error:
    java.lang.ClassCastException: android.widget.Textview cannot be cast to android.widget.Checkbox.

    Not sure if I did it right:
    Code:
    Dim p As Panel = clv.GetPanel(0)
    Dim chk As CheckBox = p.GetView(2)

    chk.Checked = 
    True
     
  9. RandomCoder

    RandomCoder Well-Known Member Licensed User

    This means that you have used the wrong index on the panel. The view with index 2 must be a TextBox and you are attempting to cast it as a CheckBox.
    You could alternatively do a scan through each view on the panel with something like....
    Code:
    For Each v As View In p.GetViewsRecursively
        
    If v Is CheckBox Then
            
    ' what you want here, maybe check tag and enable?

        
    End If
    Next
    I've done this snippet on my tablet as I don't have my laptop to hand so it might not be exactly correct but hopefully you get the idea.
     
  10. trueboss323

    trueboss323 Active Member Licensed User

    Thank you, you were right, I had to change the index , now it works fine!
     
  11. trueboss323

    trueboss323 Active Member Licensed User

    Okay now i got another problem. I followed Erel's method of GetItemFromView , this time with a label. So I ran the following code:
    Code:
    Dim index As Int
    index = clv3.GetItemFromView(
    Sender)
    Dim p As Panel
    p = clv3.GetPanel(index)
    Dim lbl As Label
    lbl = p.GetView(
    2)
    Msgbox(lbl.Text,"")
    and then I get an error

    java.lang.ClassCastException: b4a.example.customlistview cannot be cast to android.view.View

    occurring at the line

    index = clv3.GetItemFromView(Sender)
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    What is sender here? GetItemFromView is relevant when you manage an event of one of the inner controls.
     
  13. trueboss323

    trueboss323 Active Member Licensed User

    I am using Sender to try to get the current label value from the clicked panel. I want to make it so that the user taps on an item from the list view, which displays a messagebox showing the text of the selected item. Which is very similar to
    Code:
    Msgbox("Item value: " & clv3.GetValue(index)
    from the sample.
    So, I cannot figure out why:
    Code:
    Dim index As Int
        index = clv3.GetItemFromView(
    Sender)
    does not work.
     
    Last edited: Feb 22, 2015
  14. Erel

    Erel Administrator Staff Member Licensed User

    It is impossible to help you without seeing more of the code. Post the complete sub.
     
  15. trueboss323

    trueboss323 Active Member Licensed User

    Here is the complete sub.

    Code:
    Dim AchList As CustomListView
    Sub AchList_ItemClick (Position As Int, Value As Object)


    Dim index As Int
        index = AchList.GetItemFromView(
    Sender)
        
    Dim p As Panel
        p = AchList.GetPanel(index)
        
    Dim lbl As Label
        lbl = p.GetView(
    2)
        
    Msgbox("You clicked on " & lbl.text, "")


    End Sub
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    There are many mistakes in this code.

    Why do you call AchList.GetItemFromView? See my previous answer to your question.
    You need to get the panel with GetPanel(Position).
     
  17. Guardian17

    Guardian17 Active Member Licensed User

    Earlier in this thread, it is shown by Erel on Nov 17, 2014, that CustomListView is selectable in the Designer for a CustomView using a PullDown selection next to "CustomType".

    My B4A Version is 4.30.

    I have added a CustomView to a Panel in the Designer, yet when I click on the PullDown next to "CustomType", it only shows a blank box. There are no "types" to select.

    1) Is there something else that needs to be defined in order to allow CustomListView to appear in this PullDown menu? Or, is there a way to specify the CustomListView property programmatically for the CustomView that was added in the Designer?

    2) I also have CustomListView added in my code as an added module (I started using CustomListView this way programmatically, but now want to add a Layout with this CustomListView). Is having a CustomListView as a module allowable if a CustomView is also in a Layout?
     
    Last edited: Mar 1, 2015
  18. Erel

    Erel Administrator Staff Member Licensed User

    It should appear in the Custom Type list after you add the class to the project. If you do not see it then please upload your project (File - Export as zip) and we will check it.
     
  19. Guardian17

    Guardian17 Active Member Licensed User

    Erel:

    Sorry about the duplicate post. I thought that when a post is added to a thread it always pops up to the top of the Questions posts. It did not in my case, so I did not know whether anyone would see that post.

    Anyway, my project is too large to export as a ZIP file, so I made a simple example project which does the same thing (see attached ZIP file).

    When I go into the designer and I access the CustomView's CustomType pulldown, the box is empty (see attached JPG). This is after I have added the CustomListView as an existing class module, and I add the CustomListView.bas to the project.

    What am I doing wrong to not get the CustomListView in the pulldown? Does the CustomListView.bas class module have to reside in a specific folder/path?
     

    Attached Files:

  20. Erel

    Erel Administrator Staff Member Licensed User

Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice