Monday, 8 September 2014

Auto Complete Text View Tutorial in Android



Auto Complete Text View :


In Auto Complete Text View whenever we start writing a text in the Edit View than it will automatically show the available options related to that text as you stored in an array or in a database. You can see the example shown in the following screenshot :

In this example, I am storing the available options in the array and than just set the adapter for simple dropdown list available in android environment with that list.

To make this type of application you need to use the AutoCompleteTextView class available in android environment rather than simple TextView or EditView.

Let’s start coding by creating a project in Eclipse : File => New => Android Application Project and give a package name as com.javalanguageprogramming.autocompletetextdemo.

Copy the code for activity_main.xml as shown below :

   
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   >  
   
   <AutoCompleteTextView  
     android:id="@+id/autoText"  
     android:layout_width="220dp"  
     android:layout_height="50dp"  
     android:layout_marginLeft="40dp"  
     android:layout_marginTop="50dp"  
     />  
   
 </LinearLayout>  
   


In this xml file I am using AutoCompleteTextView for completing of text automatically from String array.

Now consider the code for Main.java as shown below :

 package com.javalanguageprogramming.autocompletetextdemo;  
   
 import android.app.Activity;  
 import android.os.Bundle;  
 import android.widget.ArrayAdapter;  
 import android.widget.AutoCompleteTextView;  
   
   
 public class MainActivity extends Activity {  
   
      AutoCompleteTextView autoText;  
      @Override  
      protected void onCreate(Bundle savedInstanceState) {  
           super.onCreate(savedInstanceState);  
           setContentView(R.layout.activity_main);  
             
           //initialize auto complete text view  
           autoText = (AutoCompleteTextView)findViewById(R.id.autoText);  
             
           //make an array for the suggestions  
           String[] suggest = {"aa", "all", "auto", "ask", "bb", "bat", "bad", "back", "ball", "cat", "java", "Program", "tutorial"};  
             
           //make an array adapter for viewing string array  
           ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, suggest);  
             
           //set the adapter to the auto complete text view  
           autoText.setAdapter(adapter);  
      }  
 }  
   


In this Activity, a String array named as “suggest” is used to provide the available options and ArrayAdapter for providing the views to the drop down list.

31 comments :

  1. Thanks for sharing the information. It is very useful for my future. keep sharing
    baixar facebook
    baixar whatsapp
    unblocked games

    ReplyDelete
  2. nice post for sharing Java article. its really helpful for me. keep shring on updated tutorials????????????????

    ReplyDelete
  3. Thank u for Sharing a good and useful information. Keep Sharing These type of articles

    Hadoop Training in Hyderabad

    Java Training in Hyderabad

    ReplyDelete
  4. Madaalarqam we provide best electronic trade platforms for consumer and reseller. We also develop all types of Programming applications

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete


  6. Nice blog Content.It is very informative and helpful. Please share more content. Thanks.
    JAVA Training
    JAVA Course
    JAVA Institute

    ReplyDelete
  7. CIIT Noida provides Best MCA Courses in Noida based on the current

    IT industry standards that help students to get high paying jobs in Top MNCs. CIIT provides Best MCA Training in Noida, Greater Noida, and Ghaziabad.

    CIIT is one of the trusted MCA training institutes in Noida providing practical knowledge and 100% job assistance with basic as well as advanced

    level MCA subjects. CIITN is the best MCA college in Noida, greater noida, ghaziabad, delhi, gurgaon regoin.

    At CIIT MCA classes in Noida is conducted by subject experts corporate professionals with 9+ years of experience in managing real-time and live

    projects. Sofracle Nano Specialized MCA classes Noida is the perfect blend of academic learning and practical sessions to provide maximum exposure to

    students that transform an average student into a corporate professional whom companies prefer to hire.

    Best MCA College in Noida

    ReplyDelete
  8. CIITN provides Best java training in noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs.The curriculum of our Java training institute in Noida is designed in a way to make sure that our students are not just able to understand the important concepts of the programming language but are also able to apply the knowledge in a practical way.

    if you are looking for the best oracle sql certification center in Noida, CIIT is worth to consider. CIIT is a oracle training institute offering best sql course, oracle training, sql certification and oracle dba training at affordable price. Best Oracle training in Noida.

    Java Training in Noida

    best java training in noida

    ReplyDelete
  9. Great post. Needed to write simple word that Thanks for suggestions. Keep it up! best sap simple finance online training institute in hyderabad

    ReplyDelete
  10. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    python Training in Bangalore | python Training in Bangalore

    ReplyDelete
  11. thank you for sharing useful post.
    Android programming tutorial
    welookups

    ReplyDelete
  12. Spot on with this write-up, I truly believe that this amazing site needs much more attention. I’ll probably be returning to read through more, thanks for the information!
    Java Courses in Bangalore

    ReplyDelete
  13. I got what i am seraching from last few days in your Blog. I hope you will share more info about it. Please keep sharing.
    Laptop Service center in Ameerpet
    Dell Service center in Ameerpet
    HP Service center in Ameerpet
    Lenovo Service center in Ameerpet

    ReplyDelete
  14. Thank you for sharing Amazing Blog. It's providing very useful guideline for Engineering students.
    get more: Java Programming


    ReplyDelete
  15. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
    Java Training in Bangalore

    ReplyDelete
  16. Hey there, You've done an excellent job. I will definitely digg it and personally recommend to my friends. I'm confident they'll be benefited from this website.mac reparieren berlin

    ReplyDelete
  17. wesome article! You are providing us very valid information. This is worth reading. Keep sharing more such articles. Get All JAVA Tutorials In one place , Thank you very much! ❤❤❤

    ReplyDelete
  18. Kafka clusters are fully managed for event-driven architectures. We provide 24/7 Kafka operations support for both managed and self-owned installations. Apache Kafka comes with its own set of deployment complexities as a distributed system for collecting, storing, and processing data.
    https://genexdbs.com/

    ReplyDelete
  19. Phanom Professionals Company in Bangalore provides you with a variety of JAVA software development services for the improvement of your website. We offer competitively cost services for integrating Java, developing Java websites, creating Java programs, creating Java mobile applications, migrating Java, and creating Java content management systems. Software Development Company in Bangalore is always available for you.

    ReplyDelete
  20. Thank you for the information. If you are a programmer and your are facing really bad situation with your laptop then no need to worry. Here the company ITFUX24 can help you to solve your problem. Look for their computer reparatur service today and enjoy the discount.

    ReplyDelete
  21. This Article is really helpful for me. I am pursuing Java training from Fullstack Guru's Java Classes In Pune

    ReplyDelete
  22. This article is very helpful for me. Check out the course MERN Stack Training Program

    ReplyDelete
  23. Great, post is so informative and helpfull to everyone , keep posting and checkout my blog java course in pune

    ReplyDelete
  24. Java is an object-oriented language, which means it emphasizes objects and classes. Concepts such as inheritance, polymorphism, encapsulation, and abstraction are fundamental to Java programming. click here for more information

    ReplyDelete