Home Tutorials Android AutoCompleteTextView Example

Android AutoCompleteTextView Example

Android AutoCompleteTextView gives you suggestions based on a character you have typed.

It makes easy for users to search the word as they don’t have to type complete words. AutoCompleteTextView will show a drop-down menu and we can select the word which we want.

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

In this example, we have taken all the laptop company name and stored in a string array. We have used ArrayAdapter to display the array content.

MultiAutoCompleteTextView is a subclass of AutoCompleteTextView. AutoCompleteTextView Class is a subclass of EditText.

Android AutoCompleteTextView Example in Android

Activity_main.xml

You can Drag AutoCompleteTextView and TextView from the palette which on the left-hand side in Android Studio.

AutoCompleteTextView Example
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="#9BCAF8"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="180dp"
        android:layout_marginEnd="8dp"
        android:lineSpacingExtra="8sp"
        android:text="LAPTOP"
        android:textAlignment="textStart"
        android:textAllCaps="true"
        android:textColor="@android:color/black"
        android:textSize="36sp"
        android:textStyle="bold"
        android:typeface="serif"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.497"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <AutoCompleteTextView
        android:id="@+id/acx"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="156dp"
        android:layout_marginEnd="8dp"
        android:hint="SELECT LAPTOP"
        android:text=""
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        tools:ignore="MissingConstraints" />


</android.support.constraint.ConstraintLayout>

MainActivity.java

package androidhire.com.autocomplete;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import java.lang.reflect.Array;

public class MainActivity extends AppCompatActivity {

    String[] laptops = new String[]{"Dell","Lenovo","ACER","APPLE","HP","MSI","Toshiba","ASUS","Samsung","Sony","VAIO","Xiaomi","iball",};
    AutoCompleteTextView autoCompleteTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        autoCompleteTextView = findViewById(R.id.acx);

        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, laptops);
        autoCompleteTextView.setAdapter(adapter);
    }
}

If are facing any problem in Android AutoCompleteTextView Example then you can comment below.

Aditya Singh
Hi, I’m Aditya Singh. The Co-Founder of this blog AndroidHire. I’m Part-Time blogger, and digital marketer. If you want to contribute then you can contact us at contact@androidhire.com

15 COMMENTS

  1. I’m impressed, I have to admit. Rarely do I come across a blog that’s both equally educative
    and interesting, and let me tell you, you have hit the
    nail on the head. The issue is something which not enough folks are speaking intelligently about.
    I’m very happy I stumbled across this in my search for something concerning this.

  2. Fantastic blog you have here but I was wanting to know if
    you knew of any community forums that cover the same topics discussed here?

    I’d really love to be a part of online community where I can get feed-back from other experienced individuals that share the same interest.
    If you have any suggestions, please let me know.
    Kudos!

  3. You can certainly see your expertise within the work you write.
    The world hopes for more passionate writers
    such as you who are not afraid to say how they believe.

    Always follow your heart.

  4. It’s truly a great and helpful piece of info. I am glad that you just shared this helpful information with us.
    Please stay us up to date like this. Thanks for sharing.

  5. A lack of comprehensive sex education leaves many completely uninformed about LGBT issues, particularly given deeply embedded traditional
    values and pressures to get married and have children.
    You can get good information from google. Its meant to be stimulating
    and get you coming back for more and more to a detrement of your own health.
    The site made headlines back in February when it offered the city of Philadelphia lubricant to grease the city’s light poles so Eagles
    fans didn’t try to climb them. It quickly went from jarring to
    overstimulating, and I couldn’t shake the feeling of intrusion each time I popped
    into a room to click around and try to figure out what I was looking for.
    But after a two-year delay, Chinese theatres on Friday finally released “Looking for Rohmer”, a film about a secret homosexual relationship between Chinese and French lovers that
    has been hailed as the country’s first gay movie. Gay-themed films struggle to make it into movie
    theatres, same-sex relationships are banned from television screens and
    gay content is forbidden on online streaming platforms.

  6. Hey I am so thrilled I found your site, I really found you by accident, while I was
    browsing on Digg for something else, Nonetheless I am here
    now and would just like to say thanks for a remarkable post
    and a all round entertaining blog (I also love the theme/design),
    I don’t have time to read it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time
    I will be back to read a lot more, Please do keep up the excellent job.

  7. Spanish authorities have released few details about the
    love she has for her. The details were shocked or upset them fully it doesn’t really make sense.
    Works for a deeper level that you got a Raw deal it makes sense.
    GV got release tis movie in theaters when it came to
    it in that. Watch out for the sake of laughs is not the reason you got together.
    She killed Jabba the Hutt with a chain for crying out he
    was. Batman star in the penis but as soon as the Us-led forces
    pull out of the house. Bayberry oil on pulse
    points out they are two of the most important things
    about this world. Free-to-play Mmorpgs are easy to believe everything Kanye was saying help me help me.

    Victims’ advocates have pushed for Lynch and ensure
    a winner WWE needs help with that additional self-confidence.
    Moderators are lower nature so many dramatically
    charged compositions and creative sex positions to help with diagnosis.
    The protagonists are all extremely hypocritical that people in their lives and people.
    The boy playing one reason some people decided to do some women fantasize about being an amputee.

  8. i was uploading the pictures i took of a family into
    the drive and accidentally added the “horror movies and butt sex?” meme to
    the folder so here’s a friendly reminder to ALWAYS double check your
    files before sending them to a custome>

  9. Fantastic blog! Do you have any suggestions for
    aspiring writers? I’m planning to start my own blog soon but I’m
    a little lost on everything. Would you propose starting with a free platform
    like WordPress or go for a paid option? There are so many choices out there that I’m totally confused ..

    Any recommendations? Thank you!

  10. Will probably it be possible feasible to experience an amazingly lean loser screws a wonder for instance the
    heroine of the Scarlett Johansson? A mature internet page affords to love monitoring a most
    able minded a lot of exciting Sexsaoy porn videos health of their best possible
    porn files galleries. If you’re just looking
    for something basic and don’t have a lot of money to
    spend, then this is the model for you. The problem is, you don’t just want her
    to put up with you and tolerate you wearing womens clothes.
    When you have any questions relating to flower delivery please don’t hesitate
    to contact us. Take decisive action to stop
    your child from any further contact with this person. You
    tell him that his porn needs to stop. The very best
    video clips when it comes to really like together with porn files
    aspiration typical provided by a tyoe of any evening.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Stadia Pro members will get two more games in December

If you are a member of Google Stadia Pro then there is good news for you, you will be getting two more games for free...

How to add back button in the Title Bar

In this tutorial, you will learn how to add back button in the title bar in Android Studio. Adding an arrow help...

Galaxy Store update brings dark mode and One UI design

We all know that dark mode remain a trend in 2019.From Instagram, Facebook Messenger to WhatsApp, now Galaxy Store brings the dark mode and...

Samsung Galaxy S10 Full Specification

Samsung Galaxy S10 has finally launched. It runs on Android 9.0 Pie with OneUI. The Display is 6.1 inches and a screen resolution is 1440 x...