Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

That’s No List, THIS Is a List! 52/100 Days…

  • November 4, 2019November 4, 2019
  • by Richard Clarke

You know that feeling when your college classes FINALLY help you in real life? I love when that happens.

I dipped into my object oriented programming lessons in Java to set up the ArrayAdapter used to display addresses in my app. You can find a video at the bottom of the page and a link to the source code here.

I created a class, Homes, which is used for creating objects containing each address. The Homes class contains three static Strings, each of which is an address used in this application. The objects are instantiated in the Search class and their addresses are used in an ArrayAdapter. The original adapter is copied to another dynamic adapter which is used for displaying the list of addresses. The dynamic adapter will later be updated depending on the zipcodes entered by users.

The original adapter is copied to another dynamic adapter which is used for displaying the list of addresses. The dynamic adapter will later be updated depending on the zipcodes entered by users. Currently, the list of addresses now appears under the EditText View in the Search Activity.

Home objects contain street numbers, street names, and zipcodes. At this time, three Home objects will be instantiated using each of the Static Strings. The original ArrayAdapter will be used to store the addresses used for each Home object and the dynamic ArrayAdapter will start as an exact copy.

Originally, I used an array of Strings to create the ArrayAdapter used for the ListView in the List Activity. My new approach uses a series of Home objects from which the addresses can be derived. This means I only need update the Objects in the adapter based on the zip codes entered by the user. The program now has the potential to check the zipcode attributes of each Object instead of dissecting a String for each element in the list.

Creating Homes objects using the static Strings is a simpler approach for this application. The constructor of the Homes class declares the address information when an object is instantiated. This divides the work between the Homes class, ListView, and the ArrayAdapter. The class creates the object and provides their information. This allows the ArrayAdapter to add/remove them depending on their zip code before updating the ListView. Additionally, the dynamic ArrayAdapter can be reset to it’s original state when users clear their input.

This update taught me how much I have left to learn about Android Development. I had to use some advanced Java programming concepts to finish this feature. Object Oriented Programming didn’t even cross my mind when I worked on the codingkata months ago. This made me give myself a sober look in the mirror. Yes, I want to teach developers about Android Development. But I still have a long way to go. Now is the part of my journey where I focus on building my skills.

Next, I’ll refactor the ListView in the View List activity by instantiating Home objects, same as the Search Activity. Afterwards, I’ll use the EditText view to obtain user input. Finally, I’ll add logic to the Search Activity which updates the list to display addresses matching user input.

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

Image by TeroVesalainen from Pixabay

Related

Bugfix for a Crashing Activity, 51/100 Days of Code
Capital Idea…Or Not 53/100 Days of Code
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode Android AndroidDev Java

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress