AutoCompletetextView Tutorial- android

00:26 Unknown 0 Comments

A AutoCompleteTextView is 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.

Let's demonstrate the AutoCompleteTextView:
So, You can add AutoCompleteTextview in your activity layout as:


android:layout_height="wrap_content"
android:layout_below="@id/hello"
android:ems="10"
android:hint="auto complete textview"
android:layout_marginTop="8dp"
android:id="@+id/autocomplete"/>

and finally, your activity.java file can be as:

public class MainActivity extends AppCompatActivity {
    AutoCompleteTextView text;
    String[] languages={"android", "java","IOS","JDBC","C#","C++","C"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text=(AutoCompleteTextView) findViewById(R.id.autocomplete);
        ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,languages);
        text.setAdapter(adapter);
        text.setThreshold(1);
    }
}
 You can watch video demo here:


0 comments: