Youans
Youans

Reputation: 5071

How to reverse spinner left to right without reversing the selected item?

Normal Spinner are like this :

enter image description here

when I tried to rotate it using android:rotationY="180" the selected item is also rotated seems logical

enter image description here

now the problem is the selected item is rotated making the the selected item text has no sense

the required one is the same as the first picture but with rotated spinner

Spinner XML :

<Spinner  
     android:id="@+id/privacySpinner"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_below="@id/eventPrivacy"     
     android:layout_alignParentRight="@id/eventPrivacy"
     android:prompt="@string/event_privacy"
     android:entries="@array/privacy_levels"         
     android:rotationY="180"
/>

Upvotes: 3

Views: 1119

Answers (2)

Youans
Youans

Reputation: 5071

Solved by selecting the 'item selected' since it's called back as view (textView) then rotating it back.The item selected is rotated back

  privacySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {


                public void onItemSelected(AdapterView<?> adapter, View view, int pos, long id) {

                  if(Locale.getDefault().getLanguage().equals("ar"))
                    view.setRotationY(180);// rotating the view (Selected Item) back 
                public void onNothingSelected(AdapterView<?> arg0) {
                }
            });

        }

Upvotes: 1

Blundell
Blundell

Reputation: 76516

Keep the rotation on the Spinner, but also add rotation on the textview you are using to display the text.

i.e. assign a View to the selected item, and set it's rotation back the other way.

pseudo:

spinner.setAdapter(...);
spinner.setDropDownViewResource(R.layout.my_view);

myView .. setRotationY = 180

ref http://developer.android.com/reference/android/widget/ArrayAdapter.html#setDropDownViewResource(int)

Upvotes: 0

Related Questions