Zolf
asked on
Align AutoCompleteTextView text position
Hello there,
I am developing a RTL app and want my AutoCompleteTextView widget to display the text from right to left but now it is showing on the left side. i tried doing this in my xml file but no luck.can somebody help me please.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="matc h_parent"
android:layout_height="mat ch_parent"
android:orientation="verti cal"
android:padding="10dip"
android:gravity="right">
<TextView
android:id="@+id/cusNameTV "
android:layout_width="wrap _content"
android:layout_height="wra p_content"
android:text="@string/cust omerName"
android:textColor="#FFFFFF "
android:layout_gravity="ri ght"
/>
<AutoCompleteTextView
android:id="@+id/cusName_C B"
android:layout_width="fill _parent"
android:layout_height="wra p_content"
android:gravity="right"/>
I am developing a RTL app and want my AutoCompleteTextView widget to display the text from right to left but now it is showing on the left side. i tried doing this in my xml file but no luck.can somebody help me please.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="matc
android:layout_height="mat
android:orientation="verti
android:padding="10dip"
android:gravity="right">
<TextView
android:id="@+id/cusNameTV
android:layout_width="wrap
android:layout_height="wra
android:text="@string/cust
android:textColor="#FFFFFF
android:layout_gravity="ri
/>
<AutoCompleteTextView
android:id="@+id/cusName_C
android:layout_width="fill
android:layout_height="wra
android:gravity="right"/>
ASKER
THANKS FOR YOUR FEEDBACK. I JUST POSTED part of my xml code. i have attached a screenshot of the issue.
SC20130206-101728.png
SC20130206-101728.png
I think you might need to make a custom adapter to do that. Try something along those lines.
I can't find a specific example at the moment, will check later tonight.
I can't find a specific example at the moment, will check later tonight.
The individual dropdown rows that appear in an AutoCompleteTextView is a TextView.
So you can create an XML file with a TextView, then your call to ArrayAdapter changes to accept the new TextView that you created. A screenshot of the end result is attached.
Step 1, create a custom xml file with TextView with right align gravity and other attributes. Save it in your Layout folder. Name the file text_view.xml.
autoText=(AutoCompleteText View)findV iewById(R. id.cusName _CB);
autoText.addTextChangedLis tener(this );
// Notice how the second argument when the ArrayAdapter is created is
// R.layout.text_view, which is the name of the xml file that you created
// The third argument is is the id of the TextView in text_view.xml
ArrayAdapter <String> ma = new ArrayAdapter<String>(this, R.layout.text_view, R.id.textView1, items)
autoText.setAdapter(ma);
screenshot.png
So you can create an XML file with a TextView, then your call to ArrayAdapter changes to accept the new TextView that you created. A screenshot of the end result is attached.
Step 1, create a custom xml file with TextView with right align gravity and other attributes. Save it in your Layout folder. Name the file text_view.xml.
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="right"
android:minHeight="?android:attr/listPreferredItemHeight"/>
Step 2, changes to your code (your code may be slightly different):autoText=(AutoCompleteText
autoText.addTextChangedLis
// Notice how the second argument when the ArrayAdapter is created is
// R.layout.text_view, which is the name of the xml file that you created
// The third argument is is the id of the TextView in text_view.xml
ArrayAdapter <String> ma = new ArrayAdapter<String>(this,
autoText.setAdapter(ma);
screenshot.png
ASKER
PCableGuy
thanks a lot for your help. when i use your code for the xml,i get error in my xml but when i remove the line <?xml version="1.0" encoding="UTF-8"?>
then it saves without error. then when i ran my app, i could not see the names inmy autocompletetextview btut when i put my finger on the row i get to see the name and the good news is that it is positioned to the right. but as i mentioned it does not show the list names untill i put my finger pressed on it.can you please help me solve this issue.is it got to do with the
then i tried my own xml code,but i get error when i type in the autocomplete
the error i get is
02-07 10:53:07.373: E/AndroidRuntime(16891): FATAL EXCEPTION: main
02-07 10:53:07.373: E/AndroidRuntime(16891): android.view.InflateExcept ion: Binary XML file line #1: Error inflating class <unknown>
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate r.createVi ew(LayoutI nflater.ja va:518)
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.polic y.impl.Pho neLayoutIn flater.onC reateView( PhoneLayou tInflater. java:56)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate r.createVi ewFromTag( LayoutInfl ater.java: 568)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate r.inflate( LayoutInfl ater.java: 386)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate r.inflate( LayoutInfl ater.java: 320)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ArrayAdapte r.createVi ewFromReso urce(Array Adapter.ja va:332)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ArrayAdapte r.getView( ArrayAdapt er.java:32 3)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AbsListView .obtainVie w(AbsListV iew.java:1 616)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet eTextView$ DropDownLi stView.obt ainView(Au toComplete TextView.j ava:1559)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ListView.me asureHeigh tOfChildre n(ListView .java:1241 )
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet eTextView. buildDropD own(AutoCo mpleteText View.java: 1380)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet eTextView. showDropDo wn(AutoCom pleteTextV iew.java:1 144)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet eTextView. updateDrop DownForFil ter(AutoCo mpleteText View.java: 1026)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet eTextView. onFilterCo mplete(Aut oCompleteT extView.ja va:1009)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.Filter$Resu ltsHandler .handleMes sage(Filte r.java:285 )
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.os.Handler.dispatc hMessage(H andler.jav a:99)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.os.Looper.loop(Loo per.java:1 30)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.app.ActivityThread .main(Acti vityThread .java:3693 )
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Method.i nvokeNativ e(Native Method)
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Method.i nvoke(Meth od.java:50 7)
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.os.Zy goteInit$M ethodAndAr gsCaller.r un(ZygoteI nit.java:9 07)
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.os.Zy goteInit.m ain(Zygote Init.java: 665)
02-07 10:53:07.373: E/AndroidRuntime(16891): at dalvik.system.NativeStart. main(Nativ e Method)
02-07 10:53:07.373: E/AndroidRuntime(16891): Caused by: java.lang.reflect.Invocati onTargetEx ception
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Construc tor.constr uctNative( Native Method)
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Construc tor.newIns tance(Cons tructor.ja va:415)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate r.createVi ew(LayoutI nflater.ja va:505)
02-07 10:53:07.373: E/AndroidRuntime(16891): ... 22 more
02-07 10:53:07.373: E/AndroidRuntime(16891): Caused by: java.lang.UnsupportedOpera tionExcept ion: Can't convert to dimension: type=0x1
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.content.res.TypedA rray.getDi mensionPix elSize(Typ edArray.ja va:515)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.TextView.<i nit>(TextV iew.java:7 81)
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.TextView.<i nit>(TextV iew.java:4 61)
02-07 10:53:07.373: E/AndroidRuntime(16891): ... 25 more
thanks a lot for your help. when i use your code for the xml,i get error in my xml but when i remove the line <?xml version="1.0" encoding="UTF-8"?>
then it saves without error. then when i ran my app, i could not see the names inmy autocompletetextview btut when i put my finger on the row i get to see the name and the good news is that it is positioned to the right. but as i mentioned it does not show the list names untill i put my finger pressed on it.can you please help me solve this issue.is it got to do with the
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_dropDown"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="right"
android:minHeight="?android:attr/listPreferredItemHeight"/>
ArrayAdapter <Customer> customerSpinner = new ArrayAdapter<Customer>(MainMenuActivity.this, R.layout.dropdowntext,R.id.text_dropDown, customers);
customerTextView.setAdapter(customerSpinner);
then i tried my own xml code,but i get error when i type in the autocomplete
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_dropDown"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="@android:color/white"
android:gravity="right"
android:textColor="@android:color/black"
android:textSize="@android:style/TextAppearance.Medium" />
the error i get is
02-07 10:53:07.373: E/AndroidRuntime(16891): FATAL EXCEPTION: main
02-07 10:53:07.373: E/AndroidRuntime(16891): android.view.InflateExcept
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.polic
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ArrayAdapte
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ArrayAdapte
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AbsListView
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.ListView.me
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.AutoComplet
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.Filter$Resu
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.os.Handler.dispatc
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.os.Looper.loop(Loo
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.app.ActivityThread
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Method.i
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Method.i
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.os.Zy
02-07 10:53:07.373: E/AndroidRuntime(16891): at com.android.internal.os.Zy
02-07 10:53:07.373: E/AndroidRuntime(16891): at dalvik.system.NativeStart.
02-07 10:53:07.373: E/AndroidRuntime(16891): Caused by: java.lang.reflect.Invocati
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Construc
02-07 10:53:07.373: E/AndroidRuntime(16891): at java.lang.reflect.Construc
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.view.LayoutInflate
02-07 10:53:07.373: E/AndroidRuntime(16891): ... 22 more
02-07 10:53:07.373: E/AndroidRuntime(16891): Caused by: java.lang.UnsupportedOpera
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.content.res.TypedA
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.TextView.<i
02-07 10:53:07.373: E/AndroidRuntime(16891): at android.widget.TextView.<i
02-07 10:53:07.373: E/AndroidRuntime(16891): ... 25 more
ASKER
ok got it fixed,the issue was with this line
android:textSize="@android :style/Tex tAppearanc e.Medium"
got rid of it and all worked fine. only that now the names are smaller compared to what i had before. any idea how i can increase the size
android:textSize="@android
got rid of it and all worked fine. only that now the names are smaller compared to what i had before. any idea how i can increase the size
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cheers mate
What you posted above is missing the </LinearLayout> tag at the end.
Is it possible the Java code is doing something to your layout?
Open in new window
screenshot.png