Android AutoCompleteTextView suggestions overlapping the TextView - android

I am making an application using Google maps. I am using AutoCompleteTextView to get suggestions of places. The output is as follows :
As you can see from the image, the border of the suggestion box is overlapping the TextView. I am using custom item layout with a Textview inside a Linear Layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="horizontal" >
<TextView
android:id="#+id/resultValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="#474040"
android:textSize="15sp" />
</LinearLayout>
Is there a way to bring the suggestion window down and to remove or change the colour of the grayish border of the suggestion window ?

Was doing the same thing as in the accepted answer, but was still having the overlap issue. To fix that make this call:
autocompleteView.setDropDownVerticalOffset(0);

Try like this, android:popupBackground="#EFEEEC"// change according your border you want for the suggestion box
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/text_area"
android:inputType="text|textNoSuggestions|textMultiLine"
android:paddingLeft="10dp"
android:popupBackground="#EFEEEC"
android:textColor="#333333"
android:textColorHint="#9c9c9c"
android:textSize="18sp"
android:completionThreshold="1" />
and auto_textview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:textColor="#333333"
android:layout_margin="15dp"
android:textSize="16sp" >
</TextView>
text_area9.png
Final output will look like
Hope this help you.

Use a custom drawable like
AutoCompleteTextView txtNames= (AutoCompleteTextView)findViewById(R.id.editBox);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.drawable.customlist, restList);
txtRestNames.setAdapter(adapter);
and add customlist as
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cust_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:textSize="12dp"
android:singleLine="false"/>
Change the parameters/color to suit your needs. Try it....hope it helps

Related

TextView and EditText overflow

I've got a need to display and TextView (label), EditText(Input) and TextView(suffix) in a line.
The issue I have is - if the label TextView is too long it The EditText and Suffix TextView and not drawn.
Here's my code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_weight="0"
android:padding="5dp"
android:text="Label"
android:id="#+id/label_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_weight="1"
android:id="#+id/input_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#color/dark_grey"
android:textColor="#color/black"
android:hint="text.." />
<TextView
android:padding="5dp"
android:layout_weight="0"
android:text="Suffix.."
android:background="#color/lite_grey"
android:id="#+id/suffix_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
So what I want is - even if the label is over 2-3 lines, for an EditText to appear followed by another TextView.
Any pointers would be appreciated.
Thanks!
Edit:
I've added some 'diagrams' so you can understand what I want to do a bit better.
The label to the EditText can be arbitrary length(2/3 lines), so whenever the label finishes I want an EditText to start (which is followed by another TextView showing a suffix..)
..
![This shows a 2 line label and TextView..]
Edit 2: Thanks for the responses guys!! I think #questioner has really understood what I want to do i.e. I want your 3 views to move to other lines so that they behave like they were one view - and as he has suggested i'll have to find a library for this!
How about this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="5dp"
android:text="Label"
android:id="#+id/label_text_view"
android:layout_width="100dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"/>
<EditText
android:layout_weight="1"
android:id="#+id/input_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColorHint="#color/dark_grey"
android:textColor="#color/black"
android:hint="text.."/>
<TextView
android:padding="5dp"
android:text="Suffix.."
android:layout_gravity="center_vertical"
android:background="#color/lite_grey"
android:id="#+id/suffix_text_view"
android:layout_width="100dp"
android:layout_height="wrap_content"/>
</LinearLayout>
If you want your 3 views to move to other lines so that they behave like they were one view - you should use external library for that.
Why not use a RelativeLayout instead of LinearLayout and then use android:layout_below="#+id/..." or android:layout_above="#+id/..." also android:layout_toRightOf="#+id/..." or android:layout_toLeftOf="#+id/..."
Set
android:layout_weight="1"
for each view so that they all occupy the same amount of horizontal space.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">
Try this or please expand a little more.

Text view clipping of in android

I am using a custom Toast and sometimes the text view gets clipped off if the field is too long:
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/toast" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/someotherview"
android:layout_alignBottom="#+id/someotherview"
android:layout_alignLeft="#+id/someotherview"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
I have tried virtually everything starting from android:gravity="fill" to android:ellipsize="marquee". Nothing seems to work. Does anyone know why?
Perhaps something like this would help you: http://www.androidviews.net/2012/12/autoscale-textview/
It re-sizes the textview (and the text) to fit in your other view.

Android ListView Background Color Changes on Scroll - colorCacheHint Not Fixing Issue

So I'm using a custom listview through an adapter, and on my Nexus 7 everything looks great, but on my HTC Incredible 2 I'm running into an issue where my background color changes. Here's my XML file with the cacheColorHint set. I've also tried with #AA00000. Any suggestions? I also tried setting it in the activity via setCacheColorHint, but nothing's working yet.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#AA000000"
android:cacheColorHint="#00000000">
<ImageView android:id="#+id/ExhibitListIcon"
android:contentDescription="Exhibit List Icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/ExhibitListTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#FFFFFF"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
Could you try setting the cachecolorhint in the xml where the Listview is declared, instead of the LinearLayout :
At layout file, use:
android:cacheColorHint="#0000"
OR at java code,use
listView.setCacheColorHint(Color.TRANSPARENT);
Hope this helps!!
Add below line to your listview:
android:cacheColorHint="#android:color/transparent"
listView.setCacheColorHint(Color.TRANSPARENT);

RelativeLayout Stack Buttons

I would like to align two buttons on the bottom of a relative layout that is wrapped inside of a linear layout.
I am unable to get the view favorites button to be on top of the search button. There is a big space as you can see in this image:
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/SearchRestaurantsCity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCity" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchCity" />
<TextView
android:text="#string/SearchRestaurantsState"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchState" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchState" />
<TextView
android:text="#string/SearchRestaurantsCategories"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCategories" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spRestaurantSearchCategories" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<Button
android:text="#string/btnViewFavoriteRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnViewFavoriteRestaurants"
style="#style/ButtonText"
android:padding="5dp"
android:layout_below="btnSearchRestaurants" />
<Button
android:text="#string/btnSearchRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnSearchRestaurants"
style="#style/ButtonText"
android:layout_alignParentBottom="true"
android:padding="5dp" />
</RelativeLayout>
There are 2 things wrong with the XML.
For starters, you can't refer to the button btnSearchRestaurants before it's defined.
Secondly, you've defined btnSearchRestaurants to align-parent-bottom, and then tried to define that btnViewFavoriteRestaurants would be below that button. It should be above it (as per your description).
If you're trying to put the first button I can see inside RelativeLayout, I'd try to change the following line:
android:layout_below="btnSearchRestaurants" />
for this one:
android:layout_above="#+id/btnSearchRestaurants" />
Part of the space is reserved for all the elements of the layout I can see inside the LinearLayout,and the + is because the button btnSearchRestaurants is below so it is not created yet
I think the problem is at
android:layout_below="btnSearchRestaurants"
It should be
android:layout_below="#id/btnSearchRestaurants"
In your xml code I think you should correct this line
android:layout_below="btnSearchRestaurants"
as you want it to be above the Search Restaurants button it should be
android:layout_above="#id/btnSearchRestaurants"
I changed below to above for obvious reasons (you want it above the other button not below it) and added #id/ because you will be searching for the button id.

How to add margin between radiobutton ant it's drawable?

This my current layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F5F5DC"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_dk"
android:textColor="#000000"
android:layout_gravity="center_horizontal"
android:drawablePadding="10dip"
android:text="Danish" />
<RadioButton android:id="#+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_en"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"
android:drawablePadding="10dip"
android:textColor="#000000"
android:text="English" />
</RadioGroup>
</LinearLayout>
</ScrollView>
I get this:
I would like to have some space (margin) between radiobutton an the flag (it's drawable). Is it even possible?
You can do like the following:
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="#dimen/view_size"
android:button="#null"
android:drawablePadding="100dp"
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:text="label" />
In my case, where I have a custom drawable shape, adding android:paddingDrwable attribure did not work but adding android:paddingLeft="5dp" did.
Where you are setting the image and the text give blank spaces before it.
for example: radiobutton.setText(" "+Text);.You will see the desired output.
I don't think it is possible to add space between the image and the radio button using the android apis. However, the answer to your question I think is to add some space in the image itself.
Use Relative Layout instead of Linear Layout it gives android:layout_margingleft & android:layout_margingRight to drop your radio buton & Images as well.
Also give android:padding="10dip"
Try it it will definitely work!!!!

Categories

Resources