Android Autocompletetextview pop message when no item found in suggestion - android

I am new to android.I have search a lot but doesn't find.In autocompletetextview when no item found in suggestion it should show me message "No result found". But I am not able to do it.
even if this condition not work:
if (!edittext.isPerformingCompletion()){
}
Please help me out.thanks in advance.

How do you fill your AutoCompleteTextView?
I guess that you are using a Adapter and a List of elements.
This way, you can directly search if the text entered by the user is contained in your list.
For example, you can do this on the onTextChanged method of your AutoCompleteTextView.

Show me with some codes of your project so that we can help according to you.
Else take it as sample.
array1 - Array list.
autoText - Text selected in autocomplete textView
if (!array1.contains(autoText)) {
Toast.makeText(getBaseContext(), "No Result Found", Toast.LENGTH_SHORT).show();
}

Related

autoCompleteTextView using getText().toString() get the value is not in the array

final String[] defaulttask1 = {"abc"," def"," ghi"};
final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)this.findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,defaulttask1);
autoCompleteTextView.setThreshold(0);
autoCompleteTextView.setAdapter(adapter);
I have a method using autoCompleteTextView.getText().toString().While the user types words which is not in the array, it may happen "null pointer exception"
Is there any solution that I can use autoCompleteTextView, that can search for user and let user enter text they want?
P.S. sorry, I'm not a native speaker, there might be some grammar mistake.
AutoCompleteTextView is right solution for your needs
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.
AutoCompleteTextView will allow user to type whatever he/she want but will give suggestions from array.
autoCompleteTextView.getText().toString()
will not return null in case of user types words which is not in the array. It will return whatever text is there right now in text view. It might crash if you do getText().toString() on a empty text view. So have a check before you convert textview to string
if(autoCompleteTextView.getText()!=null)
String textviewString = autoCompleteTextView.getText().toString()

Android ListView No Data Found vs. No Search Result Found

I am implementing a ContactList screen. If there is no Contact at beginning, I will show an empty experience - something like "No Contact Found, Click + button to add now". If there are contacts, just display all the contacts. Above the contact list, I have a search bar. When you enter keyword, it will do the search. And when there is no result found, it will just show empty list.
SO, I have a listView and an empty view if the list has no data. It works fine for Empty Data. However, when no result found, it still shows the empty view.
View emptyView = rootView.findViewById(android.R.id.empty);
mListView.setEmptyView(emptyView);
Is there a way of differentiating these two?
I think it's very simple.
You have to just create another new View for that "NO RESULTS FOUND".
Something like this one:
View noResultsFoundView = rootView.findViewById(android.R.id.no_results_found_view);
mListView.setEmptyView(noResultsFoundView);
How about you make a if statement if there is data in your list view set visibility to hide

Display TextView containing information from the database

How can I display a TextView containig information from the data base ?
My application displays this information as a Toast but I need it in a TextView.
displayTextView = (TextView)findViewById(R.id.text_view);
Toast.makeText(getBaseContext(), selected.getAdresse(), Toast.LENGTH_LONG).show();
Textview.settext
displayTextView.settext(selected.getAdresse().toString());
displayTextView.setText(selected.getAdresse());
See setText() for more info on developer site.
You mean displayTextView.setText(selected.getAdresse()); ?

Android Autocomplete Editext remove Suggestions Duplications

I have Auto-complete Box in Android, i am filling this Auto-complete Box with the names of Some list retrieved from the Server.
Suppose i Have ABC, XYZ, PQR, ABCC, ABCCD etc... Now on First Suggestion when i type AB: It should give me ABC, ABCC, ABCCD. Now i have selected ABC..
(Autocomplete in multivalue separated by ;)
NOw when i write ABC: It Again give ABC, ABCC, ABCCD..
Result i Want: on ABC select should be removed from the Autocomplete list. so Next suggestion should be ABCC, ABCCD only not ABC.
Please Help me out
Thanks in Advance..
Code from comment below:
myAutoComplete = (MultiAutoCompleteTextView) findViewById(R.id.talksender);
myAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, names));
You need to keep track of the selected items.
When creating the filtered list you need to filter by the string typed into the EditText AND by the items already selected.
For filtering your ArrayAdapter you need to:
Create a Filter implementaion which performs the filtering based on the EditText input AND the already selected items.
Override your ArrayAdapter's getFilter() method to return your custom Filter implementation

Shows a list of data that can be filtered while typing in SearchView Android

I don't know how to do it so, can someone give me some working codes about automatically filtering results when I type a data from the search view and get it from the external database? Thanks!
Use textwatcher on edit text.Compare strings taken by textwatcher in afterTextChange method with your list items .Make new list with matched strings and set it in adapter.Use notifyDatasetChange method on adapter to refresh the list.

Categories

Resources