Zeg du Toit
Zeg du Toit

Reputation: 64

Android Spinner RealtiveLayout as Item

is it possible to set a relativelayout array as items for spinner?

RelativeLayout[] items = new RelativeLayout[]{dep1.createObj(getContext()), dep2.createObj(getContext())};
ArrayAdapter<RelativeLayout> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, items);
_deposit.setAdapter(adapter);

i'm getting this as an output:

I would like to use the relativelayout because the object i want to display contains two strings to be displayed with left and right alignment

Upvotes: 0

Views: 99

Answers (1)

touhid udoy
touhid udoy

Reputation: 4442

No, you can only populate String in unmodified ArrayAdapter with default layout(which is pretty boring).

If you want to change the default behavior, like change the layout like you mentioned above, you have to extend an adapter like ArrayAdapter.

Here is an example of custom adapter

Upvotes: 1

Related Questions