Peterdk
Peterdk

Reputation: 16025

Android: databinding when using a ArrayAdapter: possible?

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?

Upvotes: 1

Views: 2136

Answers (1)

Dan B
Dan B

Reputation: 281

You may want to check out the SimpleAdapter:
https://developer.android.com/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.

Upvotes: 1

Related Questions