Android Question B4xPages Can't get xCLV to scroll while also using a ScrollView

Joey249

Member
Hi, I have a layout set out which uses a ScrollView and then one CustomListView on the main layout, the ScrollView works to scroll the page, however the CustomListView does not scroll*.

*The CustomListView actually scrolls when running from LeapDroid emulator, but not on my actual phone or other test devices.

I had a look at CLVNested, however that tutorial is based using two CustomListViews rather than a ScrollView + CustomListView, so I wasn't able to wrap my head around on what needed changed or if it even works for my situation, any help would be greatly appreciated :D.

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    
    
    Private ScrollView1 As ScrollView 'From "LOScrollView" Layout
    Private PnlMain As B4XView 'Panel from main layout (LOMainPage) to set ScrollView height
    Private CustomListView1 As CustomListView 'From main layout (LOMainPage)
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    
    Root.Loadlayout("LOScrollView") 'ScrollView Layout
    ScrollView1.Panel.Loadlayout("LOMainPage") 'Main Layout with CustomListView
    ScrollView1.Panel.Height = PnlMain.Height + 10%y
    
    For i = 1 To 10
        CustomListView1.AddTextItem("Item " & i,i)
        'Only Items 1-4 fits on page and will not scroll to end items
    Next
    
End Sub
 
Solution
I had a look at your projects.

Attached you find a working project for ScrollView & ScrollView, it does not work with a CustomListView.
I replaced the CustomListView1 by a ScrollView2.
You had not copied the Java code from the example, and this code must be in the Main module.
And in the EnableScrollInScrollview routine you need to put ScrollView2 in.
EnableScrollInScrollview(ScrollView2)

For the xCLV + CLVNested, i need to look deeper into it. I am not used to xCustomListViews neither to CLVNested.
First i need to study how CLVNested works with Erels' original project.

Mahares

Expert
Licensed User
Longtime User
It will not work. xCustomlistview is based on scrollview. See the answer to the same thread here:
If you continue to have problems, it is a good idea to post a demonstrative small project.
 
Upvote 1

Joey249

Member
It will not work. xCustomlistview is based on scrollview. See the answer to the same thread here:
If you continue to have problems, it is a good idea to post a demonstrative small project.
Hi Mahares,

I gave that a try from link you posted, he was attempting the same thing as myself and based on the comments it seems that he got it working however i'm still having issues with it. First off CLVNested doesn't seem to run for me at all when in B4xpages, but does in B4A. My project is in b4xpages (but for android) and can't seem to get it to debug at all even with copying over Erel's b4a example files to b4xpages.

I also seen this post, which in the comments was a method with a ScrollView and xCLV using "EnableScrollInScrollview", however that doesn't work for me either.. When compiling it, it just throws an error everytime however i'm also not positive if i'm using it correctly as I was unsure where to place the java code at the end of his comment..

I've attached 2 small limited example projects with my issue,
1) ScrollView & xCLV
This one is my attempt without CLVNested and with the "EnableScrollInScrollview" code
and
2) xCLV + CLVNested
which is the attempt with CLVNested, i've changed this around alot and had many different attempts and configurations but none ever seem to work in b4xpages, in b4a (which i don't want to use) the layout loaded but was still issues with scrolling.

I've been trying to get this working for quite a while now and searching various posts but nothing ever seems to be working for me with this issue so any help would be greatly appreciated!
 

Attachments

  • Project.zip
    31.3 KB · Views: 163
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your projects.

Attached you find a working project for ScrollView & ScrollView, it does not work with a CustomListView.
I replaced the CustomListView1 by a ScrollView2.
You had not copied the Java code from the example, and this code must be in the Main module.
And in the EnableScrollInScrollview routine you need to put ScrollView2 in.
EnableScrollInScrollview(ScrollView2)

For the xCLV + CLVNested, i need to look deeper into it. I am not used to xCustomListViews neither to CLVNested.
First i need to study how CLVNested works with Erels' original project.
 

Attachments

  • ScrollView & ScrollView.zip
    26.8 KB · Views: 163
Upvote 1
Solution

klaus

Expert
Licensed User
Longtime User
I had a deeper look at the xCLV + CLVNested.
After studying how the original project of Erel does work.
I got it to work, but i needed to split the layout into three parts.
1. The upper part.
2. The middle part with the second ScrollView.
3. The bottom part.

The scrolling works, but there is a drawback depending on what you want to put into the second ScrollView items.
If you just need to display any information, it is OK.
But, if you have any view which needs events, like Button, EdtiText etc, unfortunately, these events are lost.
You have only one event for the item. You can get the views from the selected item, but no events.
At least this is what i get, maybe i am wrong. To me, It looks like that the TouchPanel added in CLVNested consumes these events.

Attached my test project.
 

Attachments

  • xCLV_CLVNested_New.zip
    20.1 KB · Views: 162
Upvote 0

Joey249

Member
I had a deeper look at the xCLV + CLVNested.
After studying how the original project of Erel does work.
I got it to work, but i needed to split the layout into three parts.
1. The upper part.
2. The middle part with the second ScrollView.
3. The bottom part.

The scrolling works, but there is a drawback depending on what you want to put into the second ScrollView items.
If you just need to display any information, it is OK.
But, if you have any view which needs events, like Button, EdtiText etc, unfortunately, these events are lost.
You have only one event for the item. You can get the views from the selected item, but no events.
At least this is what i get, maybe i am wrong. To me, It looks like that the TouchPanel added in CLVNested consumes these events.

Attached my test project.
I've had a look at both projects you've posted, it is kind of along the lines of what i'm looking for, however the views would have events such as 2x edit texts and 1x button so the CLVNested option may not be useable for my situation.

The scrollview in scrollview option seems like a good way of going forward as it has both the text changed and button click events accessible which I need, but I also need to be able to access each item after they're created which i'm not sure if it's possible.

Example, items 0 - 10 are created. After this later on, I may need to retrieve the information from 'edtScrollViewItem.text' at say index #5 etc, as the items going into the views would be user created and can then be modified from this view, after modification the user will have an option to save the information and therefore would then need to retrieve the values of each control created.

I do appreciate all of your help though and it wasn't for nothing as if it's not possible to retrieve each item afterwards in the ScrollView+Scrollview, i'll just populate that list as read only and then have an edit button which will bring them to a page where they can then modify each item from a CLV.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the ScrollView & ScrollView progect you can of course also get any of the views in the ScrollView.
The routine below returns all texts of the EditText views.

B4X:
Private Sub GetEditTextValues As String()
    Private i As Int
    Private pnl, edt As B4XView
    Private edtTexts(ScrollView2.Panel.NumberOfViews) As String
 
    For i = 0 To ScrollView2.Panel.NumberOfViews - 1
        pnl = ScrollView2.Panel.GetView(i)
        edt = pnl.GetView(1)
        edtTexts(i) = edt.Text
        Log(edtTexts(i))
    Next
    Return edtTexts
End Sub

Each item in the ScrollView is a Panel and you can get it with:
pnl = ScrollView2.Panel.GetView(Index)
Index is the position in the ScrollView.
And then you have access to all views on this Panel with.
MyView = pnl.GetView(x)
x is the position of the view in the Panel.
In the example, the Label has index 0, the EditText has index 1 and the Button has index 2.
lbl = pnl.GetView(0)
edt = pnl.GetView(1)
btn = pnl.GetView(2)


Anyway, the xCustomListView is based on a ScrollView.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
2x edit texts and 1x button so the CLVNested option may not be useable for my situation.
Why? I tinkered a little bit with the xCLV Nested code that klaus helped you with and added a couple of my small contributions . I am pretty sure you can have click events for all buttons and some other views. if you point them out and explain what you want, we will will take a look. If you already made the decision to continue with ScrollView & ScrollView, we will stop right here.
 
Upvote 0
Top