How To Create AutoCompleteTextView in android
AutoCompleteTextView is a Automatically Show in List when User Write Text and Suggession in list of data it call AutoCompleteTextView.It is Use of Listof Country,City to Use this AutoCompleteTextView.
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <AutoCompleteTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:id="@+id/auto" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:hint="Enter Your Country Name" android:layout_marginTop="63dp" /> </RelativeLayout>
MainActivity.java
package com.example.com.autocompletetextview; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class MainActivity extends AppCompatActivity { AutoCompleteTextView actv; ArrayAdapter<String> adapter; String[] version = {"Aestro","Blender","CupCake","Donut","Eclair","Froyo","GingerBread","HoneyComb", "IceCream Sendwich","JellyBean","Kitkat","Lolipop","Marshmallow","Noghut","Oreo"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); actv = (AutoCompleteTextView)findViewById(R.id.auto); adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_item,version); actv.setAdapter(adapter); actv.setThreshold(1); } }
0 comments:
Post a Comment