Objects Are a Real Trip, 55/100 Days of Code
I attempted to replace the Strings in the ArrayAdapter with Homes objects. It didn’t go so well.
I assumed that having an ArrayAdapter of Homes objects would allow me to invoke methods from the Homes class upon them. This would simplify the process of checking the zipcodes entered by users since I could write a method which does this for me. You can find a video at the bottom of the page and a link to the source code here.
I had this idea after experimenting with the toString() method of the Homes class. The Object.toString() method returns a String representation of an object. I figured that by overriding the method, I could style the appearance of the addresses.
After this, I could replace the Strings in the ArrayAdapter with the Homes objects. Doing this automatically invokes the toString() method to display the information as needed. However, the ArrayAdapter stores these as Objects, not as Homes Objects.
While it does invoke an overridden toString() method, it doesn’t mean these objects have access to the remaining methods of the Homes class.
I’m going to try a new approach. I will continue using the Homes objects in the ArrayAdapter. However, I’ll use the overridden toString() to instantiate a new Homes object. This new object should have access to the Homes class, allowing me to use the methods as needed.
It’s a stretch, and I’m aware that creating a new Object will use more memory. Right now, this seems like my best shot at finishing this application.
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 Capri23auto from Pixabay