Android Question How to... ScrollView + Spinner (father) + Spinner (son)

edgar_ortiz

Active Member
Licensed User
HI,

I have a "scrollview" where there is a "spinner" son, which should show the information according to what is selected in the "spinner" father.

And I have NO idea how to do :(

Spinner Father = SP_STATE
Spinner Son = SP_CITY

Check the sub: TmpSpinner_ItemClick

Any help is welcome.

Thanks in Advance,

Edgar

Attached the Project
 

Attachments

  • Test_Fields.zip
    70.9 KB · Views: 82
Last edited:

edgar_ortiz

Active Member
Licensed User
Erel,
Thanks for your time,
The problem is:
  • The Father spinner contains the name of the states
  • The Son spinner contains the name of the cities
When the user select the state the I need to change the information of the Son Spinner... I have no idea how to program this?

Why does it matter that the father spinner is in a ScrollView?

Are too many fields which should be entered.

Regards,

Edgar
 
Upvote 0

derez

Expert
Licensed User
Define an array of lists() , the size equals to the number of states.
Each state will have its list, with the number in the order they appear in spinner1. These lists should be filled with the cities names.
When a state is selected, get the number (position) and fill the cities spinner with the content of the specific list(position).
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Define an array of lists() , the size equals to the number of states.
Each state will have its list, with the number in the order they appear in spinner1. These lists should be filled with the cities names.
When a state is selected, get the number (position) and fill the cities spinner with the content of the specific list(position).
Derez,

Thanks for your time...

In fact this is the "regular" way of work.

The problem is that the "spinners" are within a "scrollview" and I don't know how to change the value of the "son" "spinner".

Thanks again,

Edgar
 
Upvote 0

derez

Expert
Licensed User
Like Erel above I fail to understand why, if the spinners are on a scrollview, it changes anything in the proposed solution.
Use Spinner.AddAll (List As List)
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Like Erel above I fail to understand why, if the spinners are on a scrollview, it changes anything in the proposed solution.
Use Spinner.AddAll (List As List)
Derez

Again,

Thanks for your time.

My problem is how I identify the "son" Spinner? If you check the code "SP_MUNI", can't be accesed by "name".

Regards,

Edgar
 
Upvote 0

klaus

Expert
Licensed User
Post a small project showing the problem, it would be much easier to help you.
Without knowing what you have done and how it's impossible to give you a concrete advice.
 
Upvote 0

derez

Expert
Licensed User
My problem is how I identify the "son" Spinner
There should be only one "son" spinner, so you don't need to identify it. May be this understanding also will remove the need for scrollview.
The son spinner gets the content from one of the lists whenever a state is selected.
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Post a small project showing the problem, it would be much easier to help you.
Without knowing what you have done and how it's impossible to give you a concrete advice.

Klaus,

Thanks for your time, the project is attached in the first post.

Any help is welcome.

Regards

Edgar
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
There should be only one "son" spinner, so you don't need to identify it. May be this understanding also will remove the need for scrollview.
The son spinner gets the content from one of the lists whenever a state is selected.

Derez,

Is mandatory the use of a scrollview, There are many fields that MUST be processed... this project is just a "example".

Thanks for your time.

Regards,

Edgar
 
Upvote 0

derez

Expert
Licensed User
Here is the code that demonstrates what I wrote.
B4X:
Sub Globals
Dim statesp, citysp As Spinner
Dim lst(3) As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 2
    lst(i).Initialize
Next
lst(0).AddAll(Array As String("city 1", "city 2","city 3" ))
lst(1).AddAll(Array As String("city #1", "city #2","city #3" ))
lst(2).AddAll(Array As String("city $1", "city $2","city $3" ))

statesp.Initialize("statesp")
citysp.Initialize("citysp")
Activity.AddView(statesp,5%x,5%y, 40%x, 10%y)
Activity.AddView(citysp,55%x,5%y, 40%x, 10%y)  
statesp.Add("NY")
statesp.Add("OHIO")
statesp.Add("COLORADO")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub citysp_ItemClick (Position As Int, Value As Object)
Log(Value)  
End Sub

Sub statesp_ItemClick (Position As Int, Value As Object)
citysp.Clear
citysp.AddAll(lst(Position))  
End Sub
 
Last edited:
Upvote 0

edgar_ortiz

Active Member
Licensed User
Derez,

Thanks for your time,

Usually it's the way ... My problem is that I need this to work in a "scrollview"...

Do you know how it works in a "scrollview"

Regards,

Edgar
 
Upvote 0

derez

Expert
Licensed User
B4X:
Sub Globals
Dim statesp, citysp As Spinner
Dim lst(3) As List
Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 2
    lst(i).Initialize
Next
lst(0).AddAll(Array As String("city 1", "city 2","city 3" ))
lst(1).AddAll(Array As String("city #1", "city #2","city #3" ))
lst(2).AddAll(Array As String("city $1", "city $2","city $3" ))

statesp.Initialize("statesp")
citysp.Initialize("citysp")
   
statesp.Add("NY")
statesp.Add("OHIO")
statesp.Add("COLORADO")
sv.Initialize(150%y)
sv.Panel.AddView(statesp,5%x,5%y, 40%x, 10%y)
sv.Panel.AddView(citysp,55%x,5%y, 40%x, 10%y)
Activity.AddView(sv,0,0,100%x,100%y)
End Sub

Sub citysp_ItemClick (Position As Int, Value As Object)
Log(Value)   
End Sub

Sub statesp_ItemClick (Position As Int, Value As Object)
citysp.Clear
citysp.AddAll(lst(Position))   
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Here you are.

I added a separate Spinner reference for the city Spinner.
The 4 lines I added have are marked with 'New.

I would have done it with a Spinner array insted of temporary Spinner references, that way you know the names of the Spinners.
 

Attachments

  • Test_Fields1.zip
    71 KB · Views: 125
Upvote 0

edgar_ortiz

Active Member
Licensed User
Here you are.

I added a separate Spinner reference for the city Spinner.
The 4 lines I added have are marked with 'New.

I would have done it with a Spinner array insted of temporary Spinner references, that way you know the names of the Spinners.

Thank you very much

It WORKS !!!

Regards

Edgar
 
Upvote 0
Top