Reputation: 63
I am using auto complete fragment to search location using google places it is working fine. Now i want to remove search icon so used below code but one error is showing. code and error text are below.
Code sample
autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/header">
<Button
android:id="@+id/button5"
android:layout_width="60dp"
android:background="#1d1d6e"
android:textColor="#9999f9"
android:layout_height="25dp"
android:textSize="13sp"
android:text="@string/back"
android:textAllCaps="false"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="19dp"
android:layout_marginStart="19dp" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:layout_weight="1"
android:src="@drawable/logo" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@color/gray"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="15dp"
android:layout_gravity="center"
android:textColor="@color/black"
android:text="ADD LOCATION" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
>
<EditText
android:id="@+id/flat_no"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Flat Number/House Name"
android:paddingLeft="10dp"
android:background="@drawable/locationedittext"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/locationedittext"
android:layout_marginTop="10dp"
>
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
>
<EditText
android:id="@+id/makani"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Search By Makani"
android:paddingLeft="10dp"
android:background="@drawable/locationedittext"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/makanibutton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/makani"
app:layout_constraintTop_toTopOf="parent"
android:background="@android:drawable/ic_search_category_default" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:background="@drawable/startbutton"
android:layout_height="40dp"
android:text="SUBMIT"
android:textColor="@color/white"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@color/gray"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:text="LOCATION LIST"
android:textStyle=""
android:textColor="@color/black" />
</LinearLayout>
<ListView
android:id="@+id/locationlist"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Error Text
error: cannot find symbol variable place_autocomplete_search_button
I also want to change the hint text size of auto complete fragment
Upvotes: 0
Views: 929
Reputation: 1675
Please migrate to the latest SDK and use
AutoCompleteSupportFragment
instead ofAutoCompleteFragment
.For complete information related to migrating you can refer here.
After migrating for hiding the search button the id is,
places_autocomplete_search_button for the search Button
.
places_autocomplete_search_input for the EditText
.
So your code will be somewhat similar to this,
autocompleteSupportFragment.getView().findViewById(R.id.places_autocomplete_search_button).setVisibility(View.GONE);
Upvotes: 2