Travel App ListView Update, 48/100 Days of Code
In my latest update to the Travel app, I refactored my code to make it easier to maintain later down the line.
I updated my Travel app with a list of the addresses in the View List Activity. You can find the video on this at the bottom of the page and a link to the source code here.
To do this, I created a new layout called list_listview.xml. This file contains a TextView XML attribute which configures the styling for each item to be displayed in the list.
I also created a new layout called list.xml. This file contains a ListView which will be used for displaying each styled TextView.
Next, I added a String array in the List_Addresses class containing each address used in this project. Each String is formatted to display the Address Number, Street Name, and Zip Code on separate lines. Afterwards, I initialized two objects, a ListView object (listview) and an ArrayAdapter object (adapter). The listview object references the ListView used to display the addresses. The adapter object binds the styling configuration from the list_listview.xml and the addresses String array.
Finally, the listview object sets the adapter object as its adapter. This uses the styling in the adapter to display each element of the String array in a listview which appears when users open the View List Activity.
Styling the addresses in the ListView, creating a layout to display the them, and using an adapter to combine these configurations allowes the app to display the information.
Next, I will configure the Search_Results class to search the list using zip codes entered by the user.
For more on this, watch the YouTube video below. For the source code click here
Join the mailing list to see updates like this every week!
Coding Fanatic