Welcome Folks I am back with another blog post. In this post we will be talking about a Kotlin Library which allows you to use a Kotlin AutoCompleteTextView Widget in Android Application. The demo of the Application is given below. All the source code of the application is given below.

Download Library

Download the library here

Add the Library in Application

In your Project build.gradle you must have the following

buildscript { ... repositories { ... jcenter() } ... dependencies { ... classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } ... }

In your App build.gradle you must have the following

apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' ... dependencies { ... implementation "com.jesualex.android:autocompletelocation:$last_version" }

Get a Google Maps API Key and enabled the Google Places API for Android (Add your API Key in values):

<resources> <string name="google_places_key" translatable="false" templateMergeStrategy="preserve">YOUR_KEY_HERE</string> </resources>

Add the AutocompleteLocation into the layout:

<com.jesualex.autocompletelocation.AutocompleteLocation android:id="@+id/autocomplete_location" android:layout_width="match_parent" android:layout_height="wrap_content"/>

Full Example Source Code

Layout File:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/parentLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.jesualex.autocompletelocation.sample.MainActivity"> <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_alignParentTop="true" android:layout_alignParentStart="true" /> <com.jesualex.autocompletelocation.AutocompleteLocation android:id="@+id/autocomplete_location" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="12dp" app:background_layout="@drawable/bg_rounded_white" app:closeIcon="@drawable/ic_close" app:countryCode="au"/> </RelativeLayout>

2) Kotlin Code

MainActivity.kt