I am working on an Android project in which I am fetching addresses using Places API and displaying them using AutoCompleteTextView. Right now, it is working properly, but I want to add dot dot at the end of address, so it's not chopped.
I checked other SO links and changed some values in XML, but it is not working. Also, I would like to know what can I do to set the results to fit the width of the screen, the height seems okay.
Here is the XML code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_travel_register"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="32dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="32dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/register_travel_transparent_background"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="22dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<internetlegion.com.restaurantlunchify.Templates.MaterialDesignIconsTextView
style="@style/TextViewAppearance.Title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:text="@string/material_icon_account"
android:textColor="@color/main_color_grey_300"
android:textSize="22dp" />
<AutoCompleteTextView
android:id="@+id/restaurant_address_autocomplete"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:scrollHorizontally="true"
android:background="@drawable/edit_text_background_accent"
android:ems="10"
android:hint="Address"
android:lineSpacingExtra="1dp"
android:textColor="@color/main_color_grey_600"
android:textCursorDrawable="@drawable/edit_text_cursor_drawable_main">
</AutoCompleteTextView>
</LinearLayout>
// Other fields and all
</All layout endings>
Here is how it looks right now :
Kindly let me know what I should do. Thank you.
Edit
The adapter code for AutoComplete :
autoCompView.setAdapter(new GooglePlacesAutocompleteAdapter(this, R.layout.search_list_item));
//autoCompView.setOnItemClickListener(this);
autoCompView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selection = (String) parent.getItemAtPosition(position);
for (int i = 0; i < resultList.size(); i++) {
if (resultList.get(i).equals(selection)) {
String selectedAddress = (String) resultList.get(i);
String[] strings = selectedAddress.split(",");
if (strings.length > 2) {
autoCompView.setText(strings[0]);
restRestaurant.setRestaurantAddress(strings[0]);
restaurantCityField.setText(strings[1]);
restRestaurant.setCity(strings[1]);
} else {
autoCompView.setText(selectedAddress);
restRestaurant.setRestaurantAddress(selectedAddress);
}
autoCompView.requestFocus();
break;
}
}
}
});
autoCompView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
autoCompView.requestFocus();
}
});
class GooglePlacesAutocompleteAdapter extends ArrayAdapter implements Filterable {
public GooglePlacesAutocompleteAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
@Override
public int getCount() {
return resultList.size();
}
@Override
public String getItem(int index) {
return (String) resultList.get(index);
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
// Retrieve the autocomplete results.
resultList = autocomplete(constraint.toString());
// Assign the data to the FilterResults
filterResults.values = resultList;
filterResults.count = resultList.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
};
}
}
search_list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />