Reputation: 1619
How can I make my MultiAutoCompleteTextView to search within the strings of each list location(means search the substring too). Is there any attribute I need to set or is it even possible? For example if one of the list object is "abc123", then is it possible to include this in suggestions of autocomplete by typing 123?
Upvotes: 1
Views: 1022
Reputation: 3796
For go on this link and try this,
http://android-er.blogspot.in/2010/07/example-of-multiautocompletetextview.html
MultiAutoCompleteTextView is an editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.
You must must provide a MultiAutoCompleteTextView.Tokenizer to distinguish the various substrings.
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<MultiAutoCompleteTextView android:id="@+id/multiautocompletetextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>
Java main code:
package com.exercise.AndroidMultiAutoCompleteTextView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;
public class AndroidMultiAutoCompleteTextView extends Activity {
MultiAutoCompleteTextView myMultiAutoCompleteTextView;
String item[]={
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MultiAutoCompleteTextView myMultiAutoCompleteTextView
= (MultiAutoCompleteTextView)findViewById(
R.id.multiautocompletetextview);
myMultiAutoCompleteTextView.setAdapter(
new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, item));
myMultiAutoCompleteTextView.setTokenizer(
new MultiAutoCompleteTextView.CommaTokenizer());
}
}
Upvotes: 1