Android Question Spinner list position

fishwolf

Well-Known Member
Licensed User
Longtime User
I open a spinner hidden with a button

is it possible move position the spinner list?

Thanks

Example:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Activity.LoadLayout("Main")
   
    SpinnerBinomi.Initialize("SpinnerBinomi")
   
    SpinnerBinomi.Add("Pluto" & "-" & "Mario")
    SpinnerBinomi.Add("Kira" & "-" & "Paolo")
   
    SpinnerBinomi.Visible = False
    Activity.AddView(SpinnerBinomi, 20dip, 42dip, Activity.Width - 20dip, 40dip)
       
End Sub

Sub ButtonOpen_Click
   
    Log ("ButtonOpen_Click")
   
    Dim policy As JavaObject
    Try
        policy = SpinnerBinomi
        policy = policy.RunMethodJO("performClick", Null)
    Catch
        Log(LastException)
    End Try
   
End Sub

1697099316332.png
 
Last edited:

zed

Active Member
Licensed User
By creating a type, you can sort on several fields starting with the last and going back to the first.

B4X:
Type Test(FieldA As Int, FieldB As Int, FieldC As Int)

Dim List As List
List.Initialize
For i = 1 To 100
    List.Add(CreateTest(Rnd(1, 5), Rnd(1, 5), Rnd(1, 5)))
Next
List.SortType("FieldC", True)
List.SortType("FieldB", True)
List.SortType("FieldA", True)
For Each t As Test In List
    Log($"${t.FieldA} -> ${t.FieldB} -> ${t.FieldC}"$)
Next

Then you put the list in the spinner

B4A:
Dim sp As Spinner
sp.Initialize("SP")
sp.AddAll(List)
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
By creating a type, you can sort on several fields starting with the last and going back to the first.

B4X:
Type Test(FieldA As Int, FieldB As Int, FieldC As Int)

Dim List As List
List.Initialize
For i = 1 To 100
    List.Add(CreateTest(Rnd(1, 5), Rnd(1, 5), Rnd(1, 5)))
Next
List.SortType("FieldC", True)
List.SortType("FieldB", True)
List.SortType("FieldA", True)
For Each t As Test In List
    Log($"${t.FieldA} -> ${t.FieldB} -> ${t.FieldC}"$)
Next

Then you put the list in the spinner

B4A:
Dim sp As Spinner
sp.Initialize("SP")
sp.AddAll(List)

Thanks, but no the items, the position of list into activity, no on top-left, but center for example
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
. . . the position of list into activity, no on top-left, but center for example
There is something going on here that you are not telling us. In your first post you show this coding . . .
B4X:
    SpinnerBinomi.Visible = False
    Activity.AddView(SpinnerBinomi, 20dip, 42dip, Activity.Width - 20dip, 40dip)
That is, you add a spinner to your activity, but for some reason you make it invisible. Then you show us what looks like a screen shot with what looks like a spinner in the top left corner. This is not SpinnerBinomi because that view is hidden. Your coding refers only to SpinnerBinomi. What does your layout contain?

Why are you not simply adding SpinnerBinomi to the activity in the position that you want; in the centre, for example - and making it visible?

Edit : I have attached a demo project. There is a button; each time that you click it a spinner, near the centre of the screen, appears or disappears.
 

Attachments

  • Spinner.zip
    9 KB · Views: 40
Last edited:
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
There is something going on here that you are not telling us. In your first post you show this coding . . .
B4X:
    SpinnerBinomi.Visible = False
    Activity.AddView(SpinnerBinomi, 20dip, 42dip, Activity.Width - 20dip, 40dip)
That is, you add a spinner to your activity, but for some reason you make it invisible. Then you show us what looks like a screen shot with what looks like a spinner in the top left corner. This is not SpinnerBinomi because that view is hidden. Your coding refers only to SpinnerBinomi. What does your layout contain?

Why are you not simply adding SpinnerBinomi to the activity in the position that you want; in the centre, for example - and making it visible?

Edit : I have attached a demo project. There is a button; each time that you click it a spinner, near the centre of the screen, appears or disappears.
i need open a spinner with a graphic button

1698169873371.png


it's very simple done a hidden spinner and open from code, but i would the list near the button
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Yes, it does seem very simple. In the button click-handler you move the spinner to wherever you want it to be before making it visible.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This works:

B4X:
Sub Globals
    Private SpinnerBinomi As Spinner
    Private ButtonOpen As Button
    End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
  
    SpinnerBinomi.Initialize("SpinnerBinomi")
  
    SpinnerBinomi.Add("Pluto" & "-" & "Mario")
    SpinnerBinomi.Add("Kira" & "-" & "Paolo")
    
    Activity.AddView(SpinnerBinomi, ButtonOpen.Left, ButtonOpen.Top, 150dip, 40dip)
    Sleep(0)
    SpinnerBinomi.Visible = False
End Sub

SpinnerBinomi.Visible = False after Activity.AddView and the Sleep(0) before SpinnerBinomi.Visible = False.

1698223147214.png
1698223165677.png
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
This works:

B4X:
Sub Globals
    Private SpinnerBinomi As Spinner
    Private ButtonOpen As Button
    End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
 
    SpinnerBinomi.Initialize("SpinnerBinomi")
 
    SpinnerBinomi.Add("Pluto" & "-" & "Mario")
    SpinnerBinomi.Add("Kira" & "-" & "Paolo")
   
    Activity.AddView(SpinnerBinomi, ButtonOpen.Left, ButtonOpen.Top, 150dip, 40dip)
    Sleep(0)
    SpinnerBinomi.Visible = False
End Sub

SpinnerBinomi.Visible = False after Activity.AddView and the Sleep(0) before SpinnerBinomi.Visible = False.

View attachment 147197 View attachment 147198
Thanks, a sleep it always solution to all problems :)
 
Upvote 0
Top