26 November 2011

Working on gui for adding and deleting from the database.

I've been working all day today on a method of adding to the database. I had my dialog set up before which set the content view to a static XML layout. When it came to implementing a way of storing the information from this layout I ran in to trouble. I was setting up a listener for an "add" button within the dialog and this had an onClickListener anonymous inner class implementation. This would fetch all of the data from the input forms and add it to the database, however there was an issue with the resources it could access which was causing a NullPointerException when trying to inflate the button from the layout. There seemed to be some issue with loading the Button in with the findViewById() method which had something to do with the access level from within the inner-class to the outer-class's super-class and the fact that it used a common interface which was being overridden from with in the inner-class (A mouth-full, I know!).

I then switched my approach and used an AlertDialog instead. This worked out to be a much better solution because I was able to manually inflate the XML layout and add it as a single view to the AlertDialog builder. Then when it came to implementing another listener for the setPositiveButton method of the builder, I could just open a new database connection using the database adapter and add the transaction that way. It's a much cleaner solution that doesn't involve trying to figure out all of the inheritance and access issues.

I used the same approach for deleting transactions, however the AlertDialog builder has some pretty cool methods for building check-box lists for a dialog, and now I'm just working on a solution for deleting the selected items from the database.

Next thing I've got to do is add a method for deleting a list of transactions from the database in the database adapter class, and pass the list of selected transactions through for deleting from the above list. Some error checking to ensure the forms don't contain an empty string will also need to be put in place because I'd imagine that could generate a NullPointerException, however I haven't fully tested the input sanitisation yet.

I also would like to review how I'm going to display the list of transactions, because viewing by date doesn't look that good. I'm thinking now that maybe I should just add a tick box to each row in the table and if it's selected the user can bring up the menu and delete them that way instead as well as perform other tasks. I'll think about that some more at a later point.

No comments:

Post a Comment