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 AndroidGuys.com 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)
 http://commonsware.com 
_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?

Example:

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?

Matthias

--~--~---------~--~----~------------~-------~--~----~


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=" http://schemas.android.com/apk/res/android" ;
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="14pt"
                android:id="@+id/spinnerTarget" />

and my ArrayAdapter code looks like this:

ArrayAdapter myArrayAdapter = new
ArrayAdapter.createFromResource(this, R.array.myArrayResource,
R.layout.my_spinner_view);

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






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Sync contact

Bagaimana cara sync contact dr nokia E52 ke x10 mini pro ya oom?
Maklumin nubie ya oom
cordially,

michael

Sent with Marlboro

-- 
"

2. To know how emailprovider.db gets populated

I wanted to know how the tables in emailprovider.db gets populated
after fetching the values from the server.The configuration has been
done using eas.What class files are responsible for populating the
emailprovider.db tables.I am asking wrt Android 2.2 froyo code. Any
idea on the same will be highly helpful.

-- 

3. Not able to include jndi.jar in Android Project

4. Bluetooth device "probe"?

5. Server extras in response to licensing check

6. Build kernel android with netfilter

7. init logging (gingerbread)