Platform Used:-

  • Android Studio.

Steps To Be Followed:-

  1. Open up your Android studio and create a new empty project with the  name of your own.
  2. Now go to your activity_main.xml file to create two widgets named as Spinner and AutoCompleteTextview.
  3. Now in the java file create two instance of those widgets and assign their respective id's to them.
  4. Now create an ArrayList which will store the names of the food items.
  5. Now you can populate that Arraylist manually or from the databse, but i am populating it manually with the help of "add()".
  6. After populating the datas to the Arraylist, now we need to create two Arrayadapters which will connect those widgets to the arraylist.
  7. The reason of creating two Arrayadapters is to avoid inconsistency, because use of one Arrayadapter will filter out the items due to another widget which i have shown you in the video tutorial.
  8. Now we will set the threshold of AutocompleteTextview to 1 so that by entering one word it will start searching.
  9. Now we are all set!!!
  10. Now connect your android device and install the apk to your device for the testing purpose.

Codes:-

package com.example.nigamasis.beginnertopro;





import android.support.v7.app.AppCompatActivity;


import android.os.Bundle;


import android.widget.ArrayAdapter;


import android.widget.AutoCompleteTextView;


import android.widget.Spinner;





import java.util.ArrayList;





public class MainActivity extends AppCompatActivity {





AutoCompleteTextView suggestion_box;


Spinner items;





ArrayList foods = new ArrayList<>();





@Override


protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);





suggestion_box = (AutoCompleteTextView)findViewById(R.id.suggestion_box);


items = (Spinner)findViewById(R.id.items);





foods.add("apple");


foods.add("bannana");


foods.add("cucumber");


foods.add("guava");


foods.add("watermelon");


foods.add("grapes");


foods.add("almonds");


foods.add("pineapple");


foods.add("orange");





ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,foods);





ArrayAdapter adapter1 = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,foods);





suggestion_box.setAdapter(adapter);





items.setAdapter(adapter1);


}


}

XML File Below:-

activity_main.xml

Video Tutorial:-


THANK YOU FOR WATCHING THE VIDEO TUTORIAL
PLEASE LIKE SHARE AND COMMENT
HAVE A NICE DAY...