How Do I Change The Layout Of The Items in the Spinner Control?

by Mark Murphy » Mon, 10 Nov 2008 16:20:39 GMT

Sponsored Links

If the revised layout is the same for all of them, give the revised 
layout to the adapter constructor. You may need to use the 
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] 
objects) if your layout is more than a single TextView.

If your revised layout varies by item or needs to shift on the fly, you 
will probably need to subclass your adapter and implement getView() to 
return the View you want for each row. If you visit and 
search "Fancy ListViews", you'll find a long list of blog posts on that 
topic, though some are from the M5 SDK and will need tweaks to work on 
the current one.

Mark Murphy (a Commons Guy) 
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!


How Do I Change The Layout Of The Items in the Spinner Control?

by Matthias » Mon, 10 Nov 2008 16:37:03 GMT

 I've got my first basic app working, but I need the text inside my
spinner widget to lay out in a different way (different gravity,
different text style, etc.) How can I do this? Is there a way to give
the item a different layout setup with the Array Adapter?


ArrayAdapter myArrayAdapter = new
ArrayAdapter.createFromResource(this, R.array.myArrayResource, [change
something here?]);

If so, what do I change it to? I've tried giving it a basic layout
with a TextView and the app freezes on me. Is there some kind of
format I need to be mindful of?

Or do I need to do something with the spinner itself?



Sponsored Links

How Do I Change The Layout Of The Items in the Spinner Control?

by Matthias » Mon, 10 Nov 2008 22:16:29 GMT

 You are so totally the man!

For anyone else reading this, I created a new view called
"my_spinner_view.xml" with the following xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView  xmlns:android="" ;
                android:id="@+id/spinnerTarget" />

and my ArrayAdapter code looks like this:

ArrayAdapter myArrayAdapter = new
ArrayAdapter.createFromResource(this, R.array.myArrayResource,

And my spinner text is formatted exactly the way I want.


Other Threads

1. In need of a Context


I have developed a testagent which is started with app_process. This
testagent can do things like inject keypresses, simulate touch events
etc. More or less like the Monkey testprogram. The difference is that
I can communicate with this program over TCP/IP and trigger
functionality from my pc.

In this process I need to call Android API:s that need a Context
instance. So my question how can I get hold of one of these? I guess a
need either a Service or Activity.

I dont want this program to be visible to the user so that leaves me
with a Service. So can I start a Service without an Activity? And will
I be able to inject keypresses between Activities if  I inject from
this Service?

I run this program as root as it is today so injecting keypresses
between Activities has never been a problem as it is today.

I will only use this for testing purposes and it will never reach the
market place or anything. Just a internal testprogram for myself and
my product.


Like I said, you can't do this.  The appropriate list would probably
android-porting; I can't move the thread for you.

You can create a Service without an Activity, that's one of the points
of a
Service, but you still need to be running in a process created by the
activity manager (from an .apk with a manifest etc).

It might help if you describe what you are actually trying to do, what
context this is coming from (you are building your own platform,
something to upload to market, etc).


2. touchscreen support.

I have added touchscreen support but the calibration is not proper.
my LCD resolution is 640x480.
Has anyone tried touchscreen on different resolution LCDs?



3. Alpha Buffer support on G1

4. eglSwapBuffers slow?

5. Android Family

6. Widget process lifetime: Why not stop the service?

7. Airtell calling card - receipt