iOS Question Set ImageSlider. Types does not match.

ykucuk

Well-Known Member
Licensed User
Longtime User
Hi. i'm trying to find ImageSlider view by Tag. When i wrote code as below i got a warning "Types does not match".
How can i set ImageSlider view with return view of FindViewByTag function
Any help ?

B4X:
Dim slider As ImageSlider= FindViewByTag(p,"ImageSliderX") ' Types does not match".

 
Sub FindViewByTag(Parent As Panel, Name As String) As View

Try
For Each v As View In Parent.GetAllviewsRecursive
If Name = v.Tag And v Is ImageView Then
Return v
End If
If Name = v.Tag And v Is TextView Then
Return v
End If
If Name = v.Tag And v Is TextField Then
Return v
End If
If Name = v.Tag And v Is Button Then
Return v
End If
If Name = v.Tag And v Is Picker Then
Return v
End If
If Name = v.Tag And v Is Label Then
Return v
End If
If Name = v.Tag And v Is ImageView Then
Return v
End If
If Name = v.Tag And v Is Switch Then
Return v
End If
If Name = v.Tag And v Is Panel Then
Return v
End If
If Name = "ImageSliderX" Then '***** It's works  but i cant set view by imageslider
Return v
End If
Next
Catch
'Showerror("FindViewByTag:" & LastException  )
End Try
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. This code can be replaced with:
B4X:
Sub FindViewByTag(Parent As Panel, Name As String) As View
For Each v As View In Parent.GetAllviewsRecursive
If Name = v.Tag Then
Return v
Next
 Return Null
End Sub
There is no reason for these type checks.

2. ImageSlider is not a view by itself. A simple way to get an ImageSlider based on its name is with a global Map that maps between the name and the ImageSlider.
B4X:
Dim slider As ImageSlider = Sliders.Get(Name)
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
1. This code can be replaced with:
B4X:
Sub FindViewByTag(Parent As Panel, Name As String) As View
For Each v As View In Parent.GetAllviewsRecursive
If Name = v.Tag Then
Return v
Next
 Return Null
End Sub
There is no reason for these type checks.

2. ImageSlider is not a view by itself. A simple way to get an ImageSlider based on its name is with a global Map that maps between the name and the ImageSlider.
B4X:
Dim slider As ImageSlider = Sliders.Get(Name)

Hello Erel,

Thanks for replacing function.

I think my English is not enough how to explain well what is my problem. I created an example project about what is my problem. Code doesn't work well (cant add correct images and cant slide ). Could you run the code and try slide images in imageslider?

Thank you.
 

Attachments

  • SliderProblem.zip
    32.2 KB · Views: 174
Upvote 0
Top