• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Add to spinner from array

Hi,

I've added a spinner to one of the pages within my app. When the page(activity) loads it calls a web service and the values that are returned need to be displayed within the spinner.

I've found lots of examples where you can add values from an array but the array values are always hard coded. I need to be able to add whatever is returned from the service into an array and then add that to my spinner.

Is this possible?
 
Of course it's possible.

At the very simplest, you could stuff the values you get from the result of the web service into an array and then continue as per the examples.

A more sophisticated way would be to implement an Adapter by subclassing BaseAdapter. Your custom Adapter would bridge directly between the results of the web service and the spinner.
 
Thanks Jiminaus, I was trying to over complicate what I was doing and found a very good video tutorial about it, problem solved:)

As you're very good at responding to my posts might I ask about another situation that I'm trying to resolve?

I have an activity that displays a tablelayout with a series of items in it, you can then select one of the items and click a button to open a 2nd activity which enables the user to change various details of the selected item using a form that connects to a web service. Once the confirm button is pressed and the service runs I need the 2nd activity to close (which is fine just using the finish() command) but then when the previous activity is displayed again after the second one is closed I need the first one to essentially refresh to show the updated values. Do I need to look at using the onResume() function? Any advice would be greatly received.
 
I have an activity that displays a tablelayout with a series of items in it, you can then select one of the items and click a button to open a 2nd activity which enables the user to change various details of the selected item using a form that connects to a web service. Once the confirm button is pressed and the service runs I need the 2nd activity to close (which is fine just using the finish() command) but then when the previous activity is displayed again after the second one is closed I need the first one to essentially refresh to show the updated values. Do I need to look at using the onResume() function? Any advice would be greatly received.

I've typically seen this kind of thing done more in onStart(). But I think doing it in onResume() would also work.

See Managing the Activity Lifecycle | Activities | Android Developers for more details like the difference between onStart() and onResume().
 
Thanks again for the help! Much appreciated.

I've just tried to run my app on my phone and although it runs fine it has placed all of my class files from Eclipse onto my device? I take it I need to package it up properly into one executable?
 
Back
Top Bottom