CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

trueboss323

Active Member
Licensed User
Longtime 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?
 

trueboss323

Active Member
Licensed User
Longtime 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.

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

trueboss323

Active Member
Licensed User
Longtime 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:
B4X:
Dim p As Panel = clv.GetPanel(0)
Dim chk As CheckBox = p.GetView(2)

chk.Checked = True
 

RandomCoder

Well-Known Member
Licensed User
Longtime 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....
B4X:
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.
 

trueboss323

Active Member
Licensed User
Longtime 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....
B4X:
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.
Thank you, you were right, I had to change the index , now it works fine!
 

trueboss323

Active Member
Licensed User
Longtime 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:
B4X:
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)
 

trueboss323

Active Member
Licensed User
Longtime User
What is sender here? GetItemFromView is relevant when you manage an event of one of the inner controls.

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
B4X:
    Msgbox("Item value: " & clv3.GetValue(index)
from the sample.
So, I cannot figure out why:
B4X:
    Dim index As Int
    index = clv3.GetItemFromView(Sender)
does not work.
 
Last edited:

trueboss323

Active Member
Licensed User
Longtime User
Here is the complete sub.

B4X:
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
 

Guardian17

Active Member
Licensed User
Longtime 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:

Guardian17

Active Member
Licensed User
Longtime 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?
 

Attachments

  • CustomListViewTest1.zip
    14 KB · Views: 198
  • CustomViewPullDown.jpg
    CustomViewPullDown.jpg
    139.4 KB · Views: 284

Guardian17

Active Member
Licensed User
Longtime User
YES. After downloading the latest version of the CustomListView library, removing the old version from my project, and adding the new version to my project, the CustomListView now appears in the CustomType dropdown box.:oops:

Thank you.
 

tsteward

Well-Known Member
Licensed User
Longtime User
How would I make a customlistview resize with the panel when its resized that the CLV is attached to?
 
Status
Not open for further replies.
Top