aspose file tools*
The moose likes Android and the fly likes Is it a good idea to fill (and render) a Spinner (listview) from an external class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Is it a good idea to fill (and render) a Spinner (listview) from an external class?" Watch "Is it a good idea to fill (and render) a Spinner (listview) from an external class?" New topic
Author

Is it a good idea to fill (and render) a Spinner (listview) from an external class?

Bart Stafsson
Greenhorn

Joined: Apr 30, 2012
Posts: 3
Hi all,
Been just getting my feet wet here, so bear with me

- Have a main class that has a spinner defined in its main.xml
- Main.java is calling another Class (Geoloc.java) that looks up geolocation data of lat & long points that are sent to it through its parameter values:


I've promised myself I'd keep my code as clean as possible from the start, so I was wondering if it was possible/advisable to do the actual populating of the spinner-items inside the Geoloc.java class.

As I have it now: Geoloc.java returns a StringArray with 5 geolocation results, and Main.java takes care of the creation of the adapter and putting the StringArray into the adapter.
What I would like to do (if advisable) : to do the creation and filling of the adapter inside the Geoloc.java class.

Currently I'm not able to do this cause I'm not sure how to target the Spinner in Main.java from the external class Geoloc.java

Hopefully I explained myself clearly enough for someone to share me some insights,
thanks

EDIT
Managed to put everything (the geolookup + creation and filling of the spinner) inside the Geoloc.java class file by implementing the following code:





Still not sure if this is OK regarding Java coding standards ...
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Hello Bart Stafsson,

Welcome to CodeRanch!

Have a main class that has a spinner defined in its main.xml

What is main.xml, and why do you need an xml file?


Why getIt method is static? Why are you passing Main.this (I mean why not simply 'this')?

As I have it now: Geoloc.java returns a StringArray with 5 geolocation results

Well, a class cannot return anything. A method can return an array etc.

What I would like to do (if advisable) : to do the creation and filling of the adapter inside the Geoloc.java class.

As of now (as per you), currently, this thing is happening in Main class (its not Main.java class, its just a Main class). So, why do you want to move this functionality to Geoloc class? Also, I didn't get this 'adapter' and 'spinner' thing. What are they?

Currently I'm not able to do this cause I'm not sure how to target the Spinner in Main.java from the external class Geoloc.java

Well, if one object has one spinner, then its not a difficult task. All you'll need is a setter method for spinner and invoke it from a method of Geoloc class.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Bart Stafsson
Greenhorn

Joined: Apr 30, 2012
Posts: 3
Darryl Burke wrote:Moved from Beginning Java. Bart, you can PM a moderator or start a thread in the Ranch Office if you need to ask for a thread to be moved.

I've a feeling you won't need that information as it won't happen again

Most def not
again , my apologies ... I should take my time before I start posting away

In the meantime I have learned that it is NOT a good idea after all to fill the spinner from an external class.
Better solution would be to have the external (helper) class return a String Array to my Main class and fill the Spinner from within the main class ... thus keeping all UI 'activities' inside the main class, where they belong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it a good idea to fill (and render) a Spinner (listview) from an external class?