Android Question How to add XUI ImageSlider from code

Brandsum

Well-Known Member
Licensed User
Hi,

I'm using this ImageSlider by @Erel .

I want to add this image slider to a Panel from code. Like this:
B4X:
    Dim StoreBanner As ImageSlider
StoreBanner.Initialize(Me,"Banner")
PageScroll.Add(StoreBanner,"") 'PageScroll is a CustomListView

But I'm getting this error:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (storeinner) Create, isFirst = true **
** Activity (storeinner) Resume **
Error occurred on line: 212 (CustomListView)
java.lang.ClassCastException: in.quest.main.imageslider cannot be cast to android.view.View
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:68)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getHeight(B4XViewWrapper.java:124)
    at in.quest.main.customlistview._insertat(customlistview.java:256)
    at in.quest.main.customlistview._add(customlistview.java:96)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:355)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at in.quest.main.storeinner._showstore(storeinner.java:478)
    at in.quest.main.storeinner._loadstore(storeinner.java:470)
    at in.quest.main.storeinner._activity_resume(storeinner.java:442)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:355)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at in.quest.main.storeinner.afterFirstLayout(storeinner.java:110)
    at in.quest.main.storeinner.access$000(storeinner.java:17)
    at in.quest.main.storeinner$WaitForLayout.run(storeinner.java:82)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

What is the correct way to add this ImageSlider from code?
 

mangojack

Expert
Licensed User
Longtime User
You are attempting to pass an ImageSlider customview where the CLV is expecting a Panel.

In the Designer save a new layout containing ImageSlider .. then

B4X:
Dim p As Panel
p.Initialize("")
p.LoadLayout("imageslider")
pagescroll.Add(p,  "")

I have not played / used an ImageSlider .. but you should be able to interact with the individual sliders with the CLV.GetPanel(Index) etc ...
 
Last edited:
Upvote 0

Brandsum

Well-Known Member
Licensed User
You are attempting to pass an ImageSlider customview where the CLV is expecting a Panel.

In the Designer save a new layout containing ImageSlider .. then

B4X:
Dim p As Panel
p.Initialize("")
p.LoadLayout("imageslider")
pagescroll.Add(p,  "")

I have not played / used an ImageSlider .. but you should be able to interact with the individual sliders with the CLV.GetPanel(Index) etc ...
That's a nice workaround.

Here I found an example https://www.b4x.com/android/forum/threads/b4x-customlistview-with-multiple-imagesliders.97219/
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Upvote 0
Top