![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2ZghrARRmfnFOklR4NvY8zcFm7sUbMEyMglvFUQaEhP4HaMWUzB9cp1Wdmknz1L-dKuLCWUBTYR4UyZKF6VIP_ht9-VZ-2450yHUoHBU2Rdnu28qarzK8cXhMFY7F76idLYVomA/s320/Screenshot_2012-06-17-12-26-10.png)
My initial porting attempt also broke a small (but handy) feature from the sample Notepad app; if there were no saved notes, a special "no notes" message was displayed instead. In my app, however, this message was displaying even when there were notes present. It turns out that this feature requires your app to be designed in a very specific fashion, which happened to be the case for the sample app, but not mine. Specifically, the Activity in question needs to:
- Subclass Android's ListActivity class.
- The layout file associated with the Activity needs to contain one ListView and one TextView, and they must be id'ed using two of Android's standard View names - "list" and "no_notes".
Looking at my app, I knew that my layout file used different id names, and that my class only extended Activity. An easy fix to be sure, but there was another problem - could I still cram the Scratchpad
button onto the page? If I added it to the layout file, would it display? And even if it did, would the ListActivity accomodate the code responsible for handling click input?
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFyxUz5246Bb6eEDsCh-1YsDg30rKk5VCHv_Bj7HAQWuDp2uogMShhXfpetb7mnFh5SdMv9WgGLQ1atStxHL3JAq5KsL2p20272ljM_vbKlQA-1D3RLav6p8j2hUzEAkj6K-mLeg/s320/Screenshot_2012-06-17-12-26-04.png)
After that, it was just a matter of making a few final touch ups, such as having the cursor appear at the end of the title when opening a note, and giving notes a default title when none is entered. All told, this phase of the work took almost as long as the last, but I got far, far more done.
I'd like to end this entry with a list of additional lessons learned. All told, this was a very rewarding experience, and I feel more motivated than ever after achieving this small success.
- For the first time, I used version control on a personal project. I'm using git, as I'm used to it from work, and it worked like a charm. When I tried to refactor the app to use a ListActivity, I created a new branch: it was nice to know that, should it not work, I could revert back to a working state.
- I'm planing on going back to this app at a later date, to make some improvements. Specifically, it could use better error handling, and it would be nice to have more flexible controls for adding/deleting/editing content. Perhaps even a home screen widget for displaying the Scratchpad.
- I ran into an issue using StringBuffer; namely, I was trying to reuse the same StringBuffer instance without cleaning it out, so it kept preserving its previous content. Ideally, what I should have been doing was creating a new object every time, but sometimes I still think like a C coder, and I considered that a waste of memory. Yeah yeah, there's garbage collection, I know, but wiping the buffer was trivial, and now I feel like I can go to sleep tonight.
- Next up, a tasks app. It'll be far more complicated, but even more useful too.
No comments:
Post a Comment