Updated 2 December 2020
AutoCompleteTextView
AutoComplete TextView completes Text which is available or already reserved.when We enter character then it matches from reserved words and shows us.It shows suggestion in drop down.
AutoCompleteTextView Example
In this Example we create a AutoCompleteTextView .We use an ArrayAdapter for displaying content.
activity_main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".MainActivity"> <AutoCompleteTextView android:layout_width="match_parent" android:layout_marginTop="100dp" android:layout_height="wrap_content" android:hint="Enter your country" android:id="@+id/autoComplete_tv"/> </LinearLayout> |
In MainActivity we declare array type variable ‘country’ and store some values.
And use ArrayAdapter class and set this adapter to AutoCompleteTextView .
MainActivity
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class MainActivity extends AppCompatActivity { String country[]={"India","USA","UK","Brazil"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter<String > adapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,country); AutoCompleteTextView textView=findViewById(R.id.autoComplete_tv); textView.setThreshold(1); textView.setAdapter(adapter); } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.