Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Align AutoCompleteTextView text position

Posted on 2013-02-03
8
Medium Priority
?
1,292 Views
Last Modified: 2013-02-09
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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip"
android:gravity="right">

<TextView
    android:id="@+id/cusNameTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/customerName"
    android:textColor="#FFFFFF"
    android:layout_gravity="right"
    />

<AutoCompleteTextView
    android:id="@+id/cusName_CB"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"/>
0
Comment
Question by:zolf
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:PCableGuy
ID: 38853543
I tried your Layout code in Eclipse on an Android Phone and the text appears correctly on the right side. A screen shot is attached.

What you posted above is missing the </LinearLayout> tag at the end.

Is it possible the Java code is doing something to your layout?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip"
android:gravity="right">

<TextView
    android:id="@+id/cusNameTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="customerName"
    android:textColor="#000000"
    android:layout_gravity="right"
    />

<AutoCompleteTextView
    android:id="@+id/cusName_CB"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:textColor="#000000"/> 
    
</LinearLayout>

Open in new window

screenshot.png
0
 

Author Comment

by:zolf
ID: 38853872
THANKS FOR YOUR FEEDBACK. I JUST POSTED part of my xml code. i have attached a screenshot of the issue.
SC20130206-101728.png
0
 
LVL 12

Expert Comment

by:PCableGuy
ID: 38854875
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:PCableGuy
ID: 38858146
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.

<?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"/>      

Open in new window

Step 2, changes to your code (your code may be slightly different):
autoText=(AutoCompleteTextView)findViewById(R.id.cusName_CB);
autoText.addTextChangedListener(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
0
 

Author Comment

by:zolf
ID: 38858356
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


<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"/>

Open in new window



ArrayAdapter <Customer> customerSpinner = new ArrayAdapter<Customer>(MainMenuActivity.this, R.layout.dropdowntext,R.id.text_dropDown, customers);
				customerTextView.setAdapter(customerSpinner); 

Open in new window



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" />

Open in new window



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.InflateException: Binary XML file line #1: Error inflating class <unknown>
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.view.LayoutInflater.createView(LayoutInflater.java:518)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AbsListView.obtainView(AbsListView.java:1616)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AutoCompleteTextView$DropDownListView.obtainView(AutoCompleteTextView.java:1559)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.ListView.measureHeightOfChildren(ListView.java:1241)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AutoCompleteTextView.buildDropDown(AutoCompleteTextView.java:1380)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1144)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:1026)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:1009)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.os.Looper.loop(Looper.java:130)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.app.ActivityThread.main(ActivityThread.java:3693)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at java.lang.reflect.Method.invokeNative(Native Method)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at java.lang.reflect.Method.invoke(Method.java:507)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at dalvik.system.NativeStart.main(Native Method)
02-07 10:53:07.373: E/AndroidRuntime(16891): Caused by: java.lang.reflect.InvocationTargetException
02-07 10:53:07.373: E/AndroidRuntime(16891):       at java.lang.reflect.Constructor.constructNative(Native Method)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.view.LayoutInflater.createView(LayoutInflater.java: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.UnsupportedOperationException: Can't convert to dimension: type=0x1
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:515)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.TextView.<init>(TextView.java:781)
02-07 10:53:07.373: E/AndroidRuntime(16891):       at android.widget.TextView.<init>(TextView.java:461)
02-07 10:53:07.373: E/AndroidRuntime(16891):       ... 25 more
0
 

Author Comment

by:zolf
ID: 38858374
ok got it fixed,the issue was with this line
android:textSize="@android:style/TextAppearance.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
0
 
LVL 12

Accepted Solution

by:
PCableGuy earned 2000 total points
ID: 38861892
Try putting your own value in android:textSize="your value" instead of  "@android:style/TextAppearance.Medium"

If that doesn't work, let me know. But I believe that you are on the right track.

Error inflating class <unknown> might be the result of you and I using a different API.
0
 

Author Closing Comment

by:zolf
ID: 38870669
cheers mate
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question