Android Question CustomListView creation with code, not with designer

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi
I don't find documentation on how to programmatically create a CustomListView (using xCustomListView lib) and add it to a panel. I cannot use the designer in this case. I am adapting an existing "old style" ListView. Previous steps were Initialization and insertion on the panel. With this new view, things are different. For example, I have not clear the meaning of the CallBack request that IntelliSense proposes while initializing the CustomListView. An example should be welcome, or, at least a link to documentation.
Thanks in advance
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I declared a variable ListaCat as CustomListview. Then, when I try to Initialize, I get the request shown in the attached image.
 

Attachments

  • Immagine.png
    Immagine.png
    43.6 KB · Views: 339
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi
I don't find documentation on how to programmatically create a CustomListView (using xCustomListView lib) and add it to a panel. I cannot use the designer in this case. I am adapting an existing "old style" ListView. Previous steps were Initialization and insertion on the panel. With this new view, things are different. For example, I have not clear the meaning of the CallBack request that IntelliSense proposes while initializing the CustomListView. An example should be welcome, or, at least a link to documentation.
Thanks in advance
B4x CustomListView cannot be created at runtime.
[Callback object, generally speaking, is the object which will handle the events the... object (a View in this case) raises]
The solution is the one suggested by @mangojack
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, Thanks for replies. But "can be loaded to a panel whenever it's needed" seems not so easy. Examples load CustomListView on Activity. Trying to add the CustomListView to a panel gives a compiler error.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, no sorry, I did a little confusion, due to the fact that I am converting old code (due to your suggestion). Previously I had a Panel inside a CustomDialog , while now I have :

Dim pan As B4XView = xui.CreatePanel("")

I successfully converted the previous dialog, to use this new type of panel. It was fast and painless. But now I want to add a ListView which opens over the panel "pan", when the user clicks a button. Therefore I have declared a global CustomListView ListaCat:

Dim ListaCat as CustomListView

The error is:

pan.AddView(ListaCat,2%x,posy+deltay*2,96%x,30%y)
javac 1.8.0_121
src\b4a\identity\main.java:1664: error: incompatible types: customlistview cannot be converted to View

Thanks
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
BTW post #3 reports no link, if I don't miss something.
Before making a test project, let's do a last trial to resolve. I don't want you to waste more time.

I have now created, with designer, a Panel, with inside a CustomListView. The layout is named "Lista".

Then I declare, in Globals:
B4X:
 Private ListaCat As CustomListView
 Private ListaContainer As Panel
Inside the sub which displays the dialog, I have:
B4X:
Dim pan As B4XView = xui.CreatePanel("")
Then, as I understood, I must load the layout of ListaContainer, which contains the CustomListView ListaCat:
B4X:
 ListaContainer.LoadLayout("Lista")   ' Runtime error "Object should be first initialized"
  pan.AddView(ListaContainer,2%x,posy+deltay*2,96%x,30%y)

Now error is at Runtime: LoadLayout which says that Object must be initialized..
 
Upvote 0
Top