0% found this document useful (0 votes)
14 views17 pages

Timelineactivity (1) Lists and Adapters

The document discusses creating a TimelineActivity that will display statuses from a user's friends using a ListView and adapter. It will include a ScrollView to allow scrolling through potentially large amounts of data. An adapter is needed to efficiently connect the ListView to the database of status records, since fetching all records at once would be slow. The adapter will be cursor-based since the data comes from a database, using a SimpleCursorAdapter. A separate row layout XML file is also required to define each item in the list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views17 pages

Timelineactivity (1) Lists and Adapters

The document discusses creating a TimelineActivity that will display statuses from a user's friends using a ListView and adapter. It will include a ScrollView to allow scrolling through potentially large amounts of data. An adapter is needed to efficiently connect the ListView to the database of status records, since fetching all records at once would be slow. The adapter will be cursor-based since the data comes from a database, using a SimpleCursorAdapter. A separate row layout XML file is also required to define each item in the list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

TimelineActivity (1)

Lists and Adapters


TimelineActivity
The statuses from users friends are in the
database.
Now we will create a new activity that will
display all these statuses on the screen
It will be called the TimelineActivity
Steps
ScrollView
A way to scroll the text
Useful to make some potentially large views
scrollable
Can contain only one direct child
If we want to put multiple views into a single
view that can scroll, we first need to organize
them into a single layout.
Now we have the layout for the activity, whats the next step?
Adapters
A ScrollView will work for a few dozens records
What if the database has thousands of records
Not all of that data will be important
Fetching and printing them all will take a lot of time
Solution: Adapters
A smart way to connect a view to a data source
Typically view will be a ListView and data would come in
the form of a Cursor or Array
Adapters come as subclasses of CursorAdapter or
ArrayAdapter

Adapters
Adding ListView
Row Layout
Although timeline.xml describes the entire
activity, we also need to specify what a single
row of data looks like
The easiest way to do so is to define another
xml file
Adapters
Come in two flavors
Those that represent array data
Those that represent cursor data
Since the data in Yamba is coming from a
database, we will create a cursor-based
adapter
SimpleCursorAdapter
ViewBinder
SimpleCursorAdapter was good enough for
mapping the data in the database to listview
However, the date it shows on the screen is in
milliseconds since 1st January, 1970
In order to convert Unix timestamp to relative
time, we need to put some logic in existing
SimpleCursorAdapter
We will use setViewBinder()

You might also like