Android Question code module question

edm68

Member
Licensed User
Longtime User
I've never used modules before and am trying to tidy up my Main by breaking off into smaller modules. Hope that makes sense.
What I'm trying to do now is just populate a spinner from a different module. I've tried numerous variations and have attached my latest attempt. Not sure if I'm even using the proper type of module? I was trying to use Erel's static code module tutorial as an example, but don't know what to put in the Main.
Thanks
 

Attachments

  • test1.zip
    6.9 KB · Views: 130

derez

Expert
Licensed User
Longtime User
Code module cannot have views and spinner is a view.
Since you put the spinner in the main layout, you have it in the main activity.
The module cannot access it because it is a view, but you can get the data from there and fill it in the main.

in main:
B4X:
Sub myStart
    spnTest.AddAll(fillSpinners.fill_spnTest)
End Sub
in module:
B4X:
Public Sub fill_spnTest as string()
  Dim str() as string = Array As String("a","b","c","d"))
  Return str
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could also do it like this, passing the Spinner in the calling routine:
in main:
B4X:
Sub myStart
    fill_Spinner(spnTest, Array As String("a","b","c","d"))
End Sub
in module:
B4X:
Public Sub fill_Spinner(spn As Spinner, str as string())
    spn.AddAll(str)
End Sub

For me, filling a spinner in a code mocule is not efficient.
Instead of the code above you would have only one line in the activity module.
B4X:
spnTest.AddAll(Array As String("a","b","c","d"))
But at least you see the principle.
 
Upvote 0

edm68

Member
Licensed User
Longtime User
Thanks for the replies, will definitely check these out tomorrow.
I was just looking for an example of how to do this from another module as I've never used modules before and have a few spinners that I will need to fill, eventually from database. I just thought it might be less confusing for me if I could break it off into a module so that once I get that correct I could concentrate on other aspects.
Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…