This is a very simple tutorial on using Auto Complete Text View provided by Android SDK.
It consists of a single text box which can show suggestions based on a list of data that I provide as a source for this field. Just like Google Suggest, this also shows the nearest matches to the string that is being input by the end user.
So, here is the layout xml file:
<AutoCompleteTextView
android:id="@+id/AndroidBooks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></AutoCompleteTextView>
Nothing special. It just consists of one element.
Now in the main activity, I create an array of android books:
String[] androidBooks =
{
"Hello, Android - Ed Burnette",
"Professional Android 2 App Dev - Reto Meier",
"Unlocking Android - Frank Ableson",
"Android App Development - Blake Meike",
"Pro Android 2 - Dave MacLean",
"Beginning Android 2 - Mark Murphy",
"Android Programming Tutorials - Mark Murphy",
"Android Wireless App Development - Lauren Darcey",
"Pro Android Games - Vladimir Silva",
};
Then in the onCreate(..) method, I create an ArrayAdapter that I can pass to this AutoCompleteTextView as the data Source.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,androidBooks);
Then, I get a handle to the AutocompleteTextView, and set the arrayAdapter to it along with the Threshold. The Threshold defines the number of charaters a user should type before the suggestions start showing up.
AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.AndroidBooks);
acTextView.setThreshold(3);
acTextView.setAdapter(adapter);
That is it. Now execute and see it work.
This is the way it would look:
The example code can be downloaded here.
While this blog started off as my personal ramblings on Techncial things it has turned out to be a blog dedicated to Android. Any other technical ramblings are shared at my Technical Blog.
NOTE:
NOTE: Of late, I have been getting requests for very trivial problems that many of you are facing in your day-to-day work. This blog is not to solve your "project" problems - surely not a "Support" site.
I just love to share my knowledge in my spare time and would appreciate any questions or feedback on the articles and code I have shared. I also do appreciate thought-provoking questions that would lead me to write more articles and share.
But please do not put your day-to-day trivial problems here. Even if you do, you most probably would not get a response here.
Thanks
License
Sai Geetha's Blog by Sai Geetha M N is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Search This Blog
x
Subscribe to:
Post Comments (Atom)
hi,very nice application,but when i type * in autotext all the arraay elements should appear in screen as same as Api demos
ReplyDelete(Contacts with Hint:
Demonstates an autocomplete text box that understands the * wildcard.) in android.can u please help me
Hi, very nice example. I was wondering how to go about grabbing the index of the String[] that auto complete uses?
ReplyDeleteThanks,
Andrew
Hi,
ReplyDeletehow can i print the statement("any print statement") when the array is not match to the items.
that's rite @watson, i can't handle it too.. :(
ReplyDeletehow 'bout you now?
thanku so much for :) it really helped :)
ReplyDeletehi,
ReplyDeleteprovide me the build automation tools for android apps.
Great post. I really appereciate your work done in developing this blog.
ReplyDeleteThankfully for this unique article, I will definitely add this website to my own rss feeds, a buddy basically told me concerning this a while back.I just stumbled across your site. Pretty interesting topic, it really makes me think.
The post is pretty interesting. I really never thought I could have a good read by this time until I found out this site. I am grateful for the information given. Thank you for being so generous enough to have shared your knowledge with us.
ReplyDeleteHi Geetha, Krishna here, HOw to fill a textview with large string?
ReplyDeletehi, very helpful article, but i am facing problem in dynamically updating the auto complete adapter, and even unable to handle click event on it.
ReplyDeleteso please can you tell me appropriate way to implement it into my code of logic.
Thanks.
Hi Great tutorial ,but as you took an strings collection and made an addapter for that but i want to use an adapter which will collect to the phone contacts or say sqlite database how to do this can you explain please.........thanks in advance
ReplyDeleteThanks for the afflatus I was fatigued by appointment but i learn that action is about alive to the fullest and able every moment.
ReplyDeleteThe website is amazing, I have a look at out it continually and always has interesting information. Considered and very well-organized.Best Hosting Service
ReplyDeleteAs when i make a visit to this website, I was really curious to read this post. This post is really awesome.
ReplyDeleteI truly liked your incredible content. Please keep up the good work. Thank you very much !!!!
ReplyDeleteExcellent post. I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work.
I must show my thanks to the writer just for rescuing me from such a crisis. As a result of looking throughout the world-wide-web and seeing thoughts which were not productive, I assumed my entire life was well over. Being alive devoid of the solutions to the difficulties you’ve resolved as a result of your entire site is a serious case, as well as the kind which could have in a negative way affected my entire career if I had not discovered the website. Your personal natural talent and kindness in dealing with almost everything was helpful. I’m not sure what I would have done if I hadn’t come upon such a point like this. I am able to at this point relish my future. Thanks so much for your high quality and effective help. I will not hesitate to propose your web site to any individual who needs to have counseling on this problem.
ReplyDeleteEcommerce is a really good way to boost your business in many terms it will help in taking your business in the next level.
ReplyDeleteEcommerce Software
Thank you mam for writing this valuable tutorial.
ReplyDeleteThis is a great post; it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it. I admit, I have not been on this webpage in a long time... however it was another joy to see It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues. Great stuff as usual...
ReplyDeletecan i lose weight |
vitamind 2
Sai Geetha Can you tell me or show me how to write the android code to auto populate forms? you can e-mail me the answer at appdesignsbyjoe@gmail.com
ReplyDeleteLook forward to hearing back from you
This is a great post; it was very informative. I look forward in reading more of your work.
ReplyDeleteI think this auto suggestion box will surely help all of us. Goo and thank for this innovative idea.
ReplyDeleteI could tell how great you are in your field of interest. You could relate in each detail very well. Thank you for spending a time on sharing such informative writings to us.
ReplyDeleteThanks Dude !! :-) !!
ReplyDeleteHi,I have a small problem in AutoCompleteText view.The suggestion direction changed by default based on the EditText position(like DropDown or BottomUp).But i want to fix the suggestion direction only BottomUp is this possible.
ReplyDeletehello mem i want to that when i press dot (.) in a AutoCompleteTextView it automatically add that string which required.. like when we type in any browser www. it automatically search of website name after that when we type dot(.) it also added .com,.in automatically what i do for it.plzz reply..thanxx in advance..
ReplyDeleteLoads of thanks... :)
ReplyDeletecan't thank you enough!
ReplyDeletegood support for beginners ... really thank u sis....
ReplyDeleteSimple and Great ...... Thanks
ReplyDeleteIn android,How to Insert Auto complete text view within creating popup. Help me.
ReplyDelete