views:

129

answers:

1

I need some simple databinding for a Spinner. I want to display 2 items for each dropdownitem.
So when the user clicks the spinner I get a list like:

-------------------
Name
123456
-------------------
Name
123456
-------------------

I understand this can be done when using a Cursor, according to the databinding info on android dev. Like:

SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,
    R.layout.my_custom_spinner_item_layout,
    cur,
    new String[] {People.NAME, People.ID}, 
    new int[] {android.R.id.text1, android.R.id.text2}); 

However, I don't get my data from a database, so I don't use a cursor, I use a ArrayAdapter. Unfortunately it looks like there is no support for databinding with this adapter.

Is there a way to do this?

+1  A: 

You may want to check out the SimpleAdapter:
http://developer.android.com/intl/zh-CN/reference/android/widget/SimpleAdapter.html
You have to put your data in a list of mappings, but after that it seems like it will do what you want.

Dan B
It does work indeed, however to get the layout nice, I need to find the original spinner layout xml and mimick that.
Peterdk
Well, I got it working. However, to get it also to display checkbox in the dropdown like the normal one, I guess you need to create a custom CheckedTextView. This will do for now.
Peterdk