Android - Set Spinner text to Right -


i developing app in arabic, , there values in spinner english , arabic. so, english text aligned left , arabic aligned right.

but, want text right. tried number of ways, not getting exact solution.

my code is, have used custom spinner

import java.lang.reflect.invocationhandler; import java.lang.reflect.invocationtargetexception; import java.lang.reflect.method;   import android.content.context; import android.graphics.color; import android.util.attributeset; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.spinner; import android.widget.spinneradapter; import android.widget.textview;  public class spinnermodified extends spinner { public spinnermodified(context context) {     super(context); }  public spinnermodified(context context, attributeset attrs) {     super(context, attrs); }  public spinnermodified(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle); }  @override public void setadapter(spinneradapter orig) {     final spinneradapter adapter = newproxy(orig);      super.setadapter(adapter);      try     {         final method m = adapterview.class.getdeclaredmethod("setnextselectedpositionint", int.class);         m.setaccessible(true);         m.invoke(this, -1);          final method n = adapterview.class.getdeclaredmethod("setselectedpositionint", int.class);         n.setaccessible(true);         n.invoke(this, -1);      }     catch (exception e)     {         throw new runtimeexception(e);     } }  protected spinneradapter newproxy(spinneradapter obj) {     return (spinneradapter) java.lang.reflect.proxy.newproxyinstance(obj.getclass().getclassloader(),             new class[] { spinneradapter.class }, new spinneradapterproxy(obj)); }  /**  * intercepts getview() display prompt if position < 0  */ protected class spinneradapterproxy implements invocationhandler {     protected spinneradapter obj;     protected method getview;   protected spinneradapterproxy(spinneradapter obj)  {         this.obj = obj;      try     {      this.getview = spinneradapter.class.getmethod("getview",int.class, view.class, viewgroup.class);     }     catch (exception e)     {      throw new runtimeexception(e);     }  }      @override     public object invoke(object proxy, method m, object[] args) throws throwable     {         try         {             return m.equals(getview) && (integer) (args[0]) < 0 ? getview(                     (integer) args[0], (view) args[1], (viewgroup) args[2])                     : m.invoke(obj, args);         }         catch (invocationtargetexception e)         {             throw e.gettargetexception();         }         catch (exception e)         {             throw new runtimeexception(e);         }     }  protected view getview(int position, view convertview, viewgroup parent)throws illegalaccessexception {     if (position < 0)     {             final textview v = (textview) ((layoutinflater) getcontext()                     .getsystemservice(context.layout_inflater_service))                     .inflate(r.layout.spinner_item, parent,                             false);              v.settext(getprompt());             v.settextcolor(color.gray);              return v;     }      return obj.getview(position, convertview, parent); }   }  } 

spinner_item.xml

<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="?android:attr/listpreferreditemheight" android:layout_width="match_parent" android:gravity="right"/> 

my_lyout.xml

<com.demo.demoapp.utils.spinnermodified             android:id="@+id/search_list_spinner_2"                    android:layout_width="match_parent"             android:layout_height="35dp"             android:layout_centerhorizontal="true"             android:prompt="@string/select"             android:layout_centervertical="true"             android:layout_marginright="30dp"             android:layout_marginleft="5dp"             android:layout_toleftof="@+id/search_logo_2"             android:background="@color/transparent"             /> 

screen shot of spinner

enter image description here

i want 1000-2500 , 2500-5000 right

how can achieve this??

please help..!!

i believe that's 1 of android oddities. if wrap textview inside layout, work. example:

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="?android:attr/listpreferreditemheight" android:layout_width="match_parent">    <textview     android:layout_height="wrap_content"    android:layout_width="wrap_content"    android:layout_gravity="right"/> </framelayout> 

don't forget give id text view , call findviewbyid it


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -