In the very first Android application we saw how to create and manage a user interface, now it's time to move on to something more real and useful in some way, something to show you the underlying data.
Always on the legendary forum anddev.it I found a very simple tutorial, but enlightening. There is talk of manage a ListView with SimpleAdapter , and the idea is to have an array of data to be displayed in a list with custom layout with lots of specific icon for each element of the list. The picture on the side makes a thousand words.
The linked tutorial explains very well how to build the application, I would like to dwell only on the concept of Adapter , the generic type from which it was derived then our SimpleAdapter.
The purpose of an Adapter is to automate the bond that exists between the database and ListView which is the graphical display.
What we do is build a database in a timely manner, or we create an array of data in the form of a HashMap, and then build the Adapter past: the database, the template of the single view and how to map the fields in the database on those of the display.
eventually attack the adapter to the ListView and from that moment everything is automatic, ie when creating the list, the list itself will take the data from the database via the Adapter.
my A variant of this example was add a button and make that clicking an item was added to the list. Programmatically what I did was attach the OnClick event to add an item to the database and then use the member function notifyDataSetChanged the Adapter, which indicates that the database is varied.
0 comments:
Post a Comment