Example- How to Used MultiAutoCompleteTextView in android?
The MultiAutoCompeleteTextView used in android version API Level 1.an editable taxt view, extending autocompletetextview, that can show complete suggestions for the substring of the text,where user is typing insted of necessarily of the entire thing.
content_main.xml.
............................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_gravity="center"
android:src="@drawable/my_heder_img">
</ImageView>
<MultiAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/multiAutoCompleteTextView"
android:background="@drawable/register_cover"
android:layout_margin="30dp"
android:padding="30dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
...........................................................................................................
MainActivity.java.
............................................................................................................
package com.example.sarvesh.testproject;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;
public class MainActivity extends Activity {
@Override public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.content_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
textView.setAdapter(adapter);
textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain", "India", "Packistan", "Nepal" };
}
content_main.xml.
0 comments