Android Question Method: _add not found in: anywheresoftware.b4a.BALayout

Jakes72

Active Member
Licensed User
Longtime User
Hi All,

I am getting a strange error (See question title) when I try to add an item to a custom listview that I get from a layout I am loading.
The custom listview is index no 2 on my layout form (MyLayout) I am loading (So view 2)
So the error is basically saying that the '_add' method is not found? What am I doing wrong please help.

My code is:

B4X:
Dim pnlCategory As B4XView = xui.CreatePanel("")               
pnlCategory.SetLayoutAnimated(0, 0, 0, Width, Height)
pnlCategory.LoadLayout("MyLayout")                                  'Load my layout into the panel.

Dim lvwCategoryItems As CustomListView
lvwCategoryItems = pnlCategory.GetView(2)                       'Get the custom listview on my layout form, it is index no 2 on the form.

lvwCategoryItems.Add(pnlTest,"Test")                                 '<----- This line gives the above error.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
The custom listview might be the 3rd (index 2) view in your layout, but from the error, it looks like the 3rd view on pnlCategory is the layout. Try using GetAllViewsRecursive on pnlCategory to get a list of all the subviews so you can make sure you have the correct index.

- Colin.
 
Upvote 0

Jakes72

Active Member
Licensed User
Longtime User
Hi Colin, thanks for the advice. I did what you said and the view layout of pnlCaetgory is as follows:

TextView (0)
TextView (1)
BALAyout (2) ---> ScrollViewWrapper (0)

Now I tried this:

B4X:
lvwCategoryItems = pnlCategory.GetView(2).GetView(0)

But the error I now get is:
java.lang.RuntimeException: Method: _add not found in: anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView

I just do not know how to get the scroll view, please help.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You have got the ScrollView but it is correctly telling you that it does not implement an Add method. From the help for Scrollview.
ScrollView is a view that contains other views and allows the user to vertically scroll those views.
See the ScrollView tutorial: http://www.b4x.com/forum/basic4android-getting-started-tutorials/6612-scrollview-example.html for more information.
The ScrollView has an inner panel which actually contains the child views.
You can add views by calling: ScrollView1.Panel.AddView(...)
Note that it is not possible to nest scrolling views. For example a multiline EditText cannot be located inside a ScrollView.
 
Upvote 0

Jakes72

Active Member
Licensed User
Longtime User
Hi Agraham, thanks for the reply. I am actually trying to find the Custom Listview on my layout form which has the 'Add' method.
On my layout form I have 2 labels which are at index 0 & 1 respectively, I then have a Custom Listivew at index 2.
Th problem is that I cannot get the reference to my Listview, I am not sure if it is contained in the ScrollViewWrapper or not?
 
Upvote 0

Jakes72

Active Member
Licensed User
Longtime User
Thanks Erel, I managed to find another solution in the meantime, but i will try this for the future.
 
Upvote 0
Top