Android Question Input Slider Class and xCustomListView

red30

Well-Known Member
Licensed User
Longtime User
When I use InputSlider with xCustomListView, I get an error changing InputSlider:
B4X:
Sub InputSlider1_ValueChanged(Value As Double,UserChanged As Boolean)
        Dim index As Int= CLV_Second.GetItemFromView(Sender)
End Sub
Error:
B4X:
customlistview_getitemfromview (java line: 423)
java.lang.ClassCastException: red15530.test.inputslider cannot be cast to android.view.View
If:
B4X:
    Dim index As Int = CLV_Second.GetItemFromView(Sender)    
    Dim pnl As Panel = CLV_Second.GetPanel(index)
    Dim sb As InputSlider = pnl.GetView(6)
    sb.SetValue(25)
I get:
B4X:
B4A Version: 8.30
Parsing code.    (0.11s)
Compiling code.    (0.28s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
Generating R file.    (0.12s)
Compiling generated Java code.    Error
B4A line: 369
Dim sb As InputSlider = pnl.GetView(6)
javac 1.8.0_161
src\red15530\ap\full\mod6.java:558: error: incompatible types: View cannot be converted to inputslider
_sb = (red15530.test.inputslider)(_pnl.GetView((int) (6)).getObject());
                                    ^
How can I use Input Slider Class and xCustomListView?
 

red30

Well-Known Member
Licensed User
Longtime User
That's right!
In the designer I add InputSlider1
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private MyCLV As CustomListView
  
    Private Button1 As Button
    Private InputSlider1 As InputSlider
    Private Label1 As Label
  
    Type ItemValue5 (Button1 As Button, InputSlider1 As InputSlider, Label1 As Label)
  
    Dim xui As XUI
    Dim Zash=0
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
    InputSlider1.SetMaxVal(10)
    For i = 1 To 10
        Dim iv5 As ItemValue5
        iv5.Initialize
        MyCLV.Add(CreateItem5(iv5,"Test"&i,i),iv5)
    Next
    Zash=1
End Sub

Sub CreateItem5(iv5 As ItemValue5,Title_5 As String,ind As Int) As Panel
    Dim p5 As Panel
    p5.Initialize("")
    Activity.AddView(p5, 0, 0, 100%x,20%y)
    p5.LoadLayout("Item")
    p5.RemoveView 'remove from parent
    Button1.Text = Title_5
    Label1.Text=ind
    InputSlider1.SetValue(ind)
    Return p5
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    Dim index As Int = MyCLV.GetItemFromView(Sender) 
    Dim pnl As Panel = MyCLV.GetPanel(index)
    Dim sb As InputSlider = pnl.GetView(1)
    sb.SetValue(20)
End Sub

Sub InputSlider1_ValueChanged(Value As Int)
    If Zash=1 Then
        Dim index As Int= MyCLV.GetItemFromView(Sender)
        Dim pnl As Panel = MyCLV.GetPanel(index)
        Dim lbl As Label = pnl.GetView(2)
        lbl.Text=Value
    End If
End Sub
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I guess that InputSlider is a custom view. A custom view is not a view by itself. The base view (usually a panel) will be returned instead.

You can do something like:
B4X:
InputSlider1.GetBase.Tag = InputSlider1

Then you will be able to get the InputSlider instance from the panel tag property.
I do not understand ... I tried, it still does not work.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you zip and post your project so that I can run it. The input slider class is a really old class which may need amending slightly to allow you to do this.

Which version of the input slider are you running, there have been some additional versions posted by others, I just want to make sure which one you are running.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This now works, just added the method GetBase to the input slider, stored the InputSlider Customview object on it's own base pane so that it can be easily retrieved and amended the Button1_Click and InputSlider1_Valuechanged subs to get the correct objects.
 

Attachments

  • CLV.zip
    18 KB · Views: 304
Upvote 0

stevel05

Expert
Licensed User
Longtime User
BTW, I had to remove the SetMaxValue from Activity_Create as there is not an input slider in the MainLayout. If you want to use it, you will need to add it in the CreateItem5 sub so it is applied to each InputSlider as it is created.
 
Upvote 0
Top