xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    andr" />

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    andr" />

info@thistimebd.com

Thursday 21st of November 10:16:09pm

auto complete text

activity_main.xml


    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:padding="10dp"

    tools:context="com.sam.web.autocompletetext.MainActivity">


   

        android:gravity="center"

        android:textColorHint="#2294ff"

        android:textStyle="bold|italic"

        android:textSize="20sp"

        android:hint="Enter your country_name"

        android:id="@+id/autoCompleteTextViewId"

        android:layout_width="match_parent"

        android:layout_height="wrap_content" />





MainActivity.java


package com.sam.web.autocompletetext;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.AutoCompleteTextView;

import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    private AutoCompleteTextView autoCompleteTextView;

    private String[] countryNames;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        countryNames=getResources().getStringArray(R.array.country_name);


        autoCompleteTextView=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextViewId);

        ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,countryNames);

        autoCompleteTextView.setThreshold(1);

        autoCompleteTextView.setAdapter(adapter);


        autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override

            public void onItemClick(AdapterView parent, View view, int position, long id) {

                String value=autoCompleteTextView.getText().toString();

                Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show();

            }

        });

    }

}




string.xml



    AutoCompleteText

   

        afganistan

        bangladesh

        canada

        cargo

        uk

        usa

        london

        syria

        saudia

        turkey

        nepal

        brazil

        india

        russia

        syralion

        ujbekistan

        uruguay

        italy

        australia

        newzialand