How do I center text in a spinner in Android -



How do I center text in a spinner in Android -

i have spinner in linearlayour.

i trying center text in spinner:

this xml element:

<spinner android:id="@+id/project_spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginright="50dp" android:layout_marginleft="50dp" android:padding="1dip" android:prompt="@string/spinner_title" />

the declaration of spinner in activity:

// creating adapter spinner arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, nomprojets); // drop downwards layout style - list view radio button dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); // attaching info adapter spinner spinner.setadapter(dataadapter);

thanks,

the component creates items spinner adapter. should customize (by overriding getview() method) homecoming centered textview widgets.

in case, replace new arrayadapter<string> ... initialization code:

arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, nomprojets) { @override public view getview(int position, view convertview, viewgroup parent) { homecoming setcentered(super.getview(position, convertview, parent)); } @override public view getdropdownview(int position, view convertview, viewgroup parent) { homecoming setcentered(super.getdropdownview(position, convertview, parent)); } private view setcentered(view view) { textview textview = (textview)view.findviewbyid(android.r.id.text1); textview.setgravity(gravity.center); homecoming view; } };

android

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -