Can someone explain the difference between MultiAutoCompleteTextView and AutoCompleteTextView?
AutocompleteTextView only offers suggestions about the whole sentence and MultiAutoCompleteTextView offers suggestions for every token in the sentence. You can specify what is the delimiter between tokens.
String[] words=new String[] {
"word1", "word2", "word3", "word4", "word5"
};
MultiAutoCompleteTextView macTv = (MultiAutoCompleteTextView) this.findViewById(R.id.mac_tv);
ArrayAdapter<String> aaStr = new ArrayAdapter<String>(this,android.R.layout.dropdown_item,words);
macTv.setAdapter(aaStr);
macTv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer() );
and:
<MultiAutoCompleteTextView
android:id="#+id/mac_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>
with this example the suggestion comes after every comma.
The choice between using the AutoCompleteTextView or the MultiAutoCompleteTextView comes down to whether or not the user should be allowed to input only "one item" as provided by the adapter, or "multiple items."
So for example, if you were writing an email app, and you wanted the "To:" field to be an autocomplete field, pulling matches from an address book, chances are you want to allow the user to pick multiple recipients for a message, and would make this field a MultiAutoCompleteTextView.
On the other hand, the "From:" field in the same example email app, you would need to enforce only a single selection by the user from their configured email accounts. And so an AutoCompleteTextView would be appropriate here.
Difference between AutoCompleteTextView and MultiAutoCompleteTextView
AutoCompleteTextView Vs MultiAutoCompleteTextView
AutocompleteTextView only offers suggestions about the whole sentence MultiAutoCompleteTextView offers suggestions for every token in the sentence. You can specify what is the delimiter between tokens.
AutoCompleteTextView is used for selecting single Item MultiAutoCompleteTextView is used for for selecting multiple Items by using a delimiter(such as comma) in betwwen them.
the “From:” field in example of email app, you would need to enforce only a single selection by the user from their configured email accounts. If you were writing an email app, and you wanted the “To:” field to be an autocomplete field, getting matches from an address book, chances you want to allow the user to pick multiple recipients for a message, and would make this field a MultiAutoCompleteTextView
AutocompleteTextView only offers suggestions about the whole
sentence
MultiAutoCompleteTextView offers suggestions for every token in the
sentence.
You can specify what is the delimiter between tokens also set the first or any no. of characters using setThreshold() with MultiAutoCompeleteTextView control in Android.
Related
I have been wracking my brains but have come up short. https://developer.android.com/training/search/setup.html I am trying to figure out how to find out when the user has clicked on a voice button or for that matter what the user has said. This is independent of what the user types on a searchview. So, the https://developer.android.com/reference/android/widget/SearchView.html#setOnSearchClickListener(android.view.View.OnClickListener).. will not work.
Other than extending the SearchView and putting in my own click listener is there a way for me to find out when the user has clicked on the voice icon?
Just like any search, the result is found in SearchManager.QUERY. However, for voice search, SearchManager.USER_QUERY will be empty as per its documentation:
Intent extra data key: Use this key with content.Intent.getStringExtra() to obtain the query string typed in by the user. This may be different from the value of QUERY if the intent is the result of selecting a suggestion. In that case, QUERY will contain the value of SUGGEST_COLUMN_QUERY for the suggestion, and USER_QUERY will contain the string typed by the user.
I have a requirement for implementing an edit text that the user can type in a anything but when they type in a new word that starts with '#' the autocomplete should start showing potential users.
I understand how to use the AutoCompleteTextView function for filtering. But I am not sure how to go about capturing the characters from the last word after the '#' symbol (ignoring any previous words).
Consequently when the user has been selected from the AutoCompleteTextView list, it should replace the the word with '#', eg.
"This is a message for #steve"
when the user clicks on "Steve" from the list, the text should replace to:
"This is a message for Steve"
I also need to obtain the string in a form that I can send off to the server. i.e. from the above example I would need to send off the string:
"This is a message for [username:steve#bloggs.com, id:44]."
I have looked at https://github.com/splitwise/TokenAutoComplete
Which seems great for typing emails in a list, but I am not sure how to cater it for my needs. Bare in mind, I need to support multiple/duplicate mentions:
eg
"This is a message for Steve and Bob. this is the second sentence in the message for Bob"
If anyone knows or has done anything like this, would really appreciate it!
I ended up using the spyglass library from linkedin which does exactly what I was looking for. It provides a MentionsEditText (that can be customised). I also used a ListPopupWindow to show the suggestions in a list (like an AutoCompleteTextView).
Here is the link...
https://github.com/linkedin/Spyglass
The following method will extract words starting with "#":
private void parseText(String text) {
String[] words = text.split("[ \\.]");
for (int i = 0; i < words.length; i++) {
if (words[i].length() > 0
&& words[i].charAt(0) == '#') {
System.out.println(words[i]);
}
}
}
Once you have the words, use your auto complete filter and finally replace text using String.replace.
I have an app in android that handles reporting about classes taken.
I have a edittext that is for entering the teacher's name, but there is a possibilty that there are more then one teacher.
I want to put all the names in the same edittext, similar to how its on gamil -
where you send a mail in gmail, you can enter multiple addresses (multiple values).
Best would be to have an autocompletetextview that will enalbe multiple names (values) in it, and the user can choose between pre-defined name options.
any ideas??
thnaks
Yes there is something you need.
You can use MultiAutoCompleteTextView from android widgets.
but here is more customizable version of it check this link TokenAutoCompleteTextView
It is same like gmail bubbles.It extends MultiAutoCompleteTextView from android widgets.
Hope it will help.Thanks
I am writing simple login activity.
I have login edit text and password edit text.
I am kepping login and pasword via sharedpreferences.
I want to make login field to rember previous logins (eg "aaa" and "aab") so when you type in edit text it give you some options and you can choose them to outo complite it.
How it can be done?
You should use AutoCompleteTextView instead of simple EditText
check dev link http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
also check this link for detail http://www.javatpoint.com/android-autocompletetextview-example
You can use AutoCompleteTextView for the login field, and use a suitable adapter to display the values. If you are remembering the previous login IDs, then, you can store them in SQLite DB and use CursorAdapter to populate the auto complete text view.
I have implemented search dialog and online search suggestion. But I want when user click on suggestion to copy string from suggestion list to search dialog and when user click on search button to start searching. Now when user click on suggestion searching is automatic start.
Take a look at http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#RewritingQueryText which lists 3 different approaches to do this as per below:
1) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromText" value. In this case, the content from the suggestion's SUGGEST_COLUMN_TEXT_1 column is used to rewrite the query text.
2) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromData" value. In this case, the content from the suggestion's SUGGEST_COLUMN_INTENT_DATA column is used to rewrite the query text. This should only be used with URI's or other data formats that are intended to be user-visible, such as HTTP URLs. Internal URI schemes should not be used to rewrite the query in this way.
3) Provide a unique query text string in the SUGGEST_COLUMN_QUERY column of your suggestions table. If this column is present and contains a value for the current suggestion, it is used to rewrite the query text (and override either of the previous implementations).