Android AutoCompleteTextview With Custom Layout

Опубликовано: 25 Май 2020
на канале: Coding Demos
7,378
38

Hi and welcome to another tutorial from CodingDemos :)

Today you will learn how to use Android AutoCompleteTextview that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down list from which the user can choose an item to replace the content of the edit box.

You will also learn how to create a custom Android AutoComplete by changing the text size, text style, and add a line that separates the items.

You will create a custom layout that contains Android textview and view. This textview will show the name of the item while the view is used to show a horizontal line that will separate the items inside AutoCompleteTextview drop down.

Here are the steps:
1- Open up Android Studio.

2- Add Android AutoCompleteTextview inside the activity_main.xml file.

3- Open up MainActivity.java file and reference the view AutoCompleteTextview based on its ID.

4- Create an ArrayAdapter that will hold the items of AutoCompleteTextview. This adapter will link to the items that were initialized inside the Strings.xml file.

5- Build and run the app to see the result.

6- Now that you have the basic AutoCompleteTextview showing successfully inside the emulator, next you need to customize the appearance by creating a custom layout called layout_item_autocomplete.xml file.

7- Inside layout_item_autocomplete.xml file, you need to add a textview that will be used to show the name of the item, while you add the other view that will be used as a horizontal line that separates the items. Now change the text size and style of this textview.

8- Next you need to change the ArrayAdapter resource file with the custom file that you've just created together with the textview ID.

9- Build and run the app to see the output.

10- You can change the background color of the AutoCompleteTextview drop down using android:popupBackground.

11- You can set a hint for the AutoCompleteTextview using android:completionHint.

12- You can also change the color of the AutoCompleteTextview selected item using android:dropDownSelector.

13- Build and run the app to see the final result :)

Links:
Android developer documentation: https://developer.android.com/referen...
Website: https://www.codingdemos.com
FaceBook:   / codingdemos  


Смотрите видео Android AutoCompleteTextview With Custom Layout онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Coding Demos 25 Май 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 7,37 раз и оно понравилось 3 людям.