Listing 916 reslayoutdiaryrowxml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="wrap_content"

android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignLeft="@+id/name" android:layout_below="@+id/name" xmlns:android=""


<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content" android:id="@+id/name" android:layout_marginRight="4dp" android:text="Diary Title " android:textStyle="bold" android:textSize="16dip" /> <TextView android:id="@+id/datetext"


android:layout_height="wrap_content" android:text="Date Recorded" android:textSize="14dip" /> </RelativeLayout>

The activity extends ListActivity to display a ListView. Inside this class are two inner classes defined: MyDiary is a data class to hold the content of the diary entry (title, content, and date), and DiaryAdapter is a BaseAdapter class to handle data retrieval from the database (using getdata()).The following methods are derived from BaseAdapter and called by ListView:

■ getCount() —Returns how many items on the adapter

■ getItem()—Returns the item specified

■ getItemID()—Returns the ID of item (for this example, there is no item ID)

Note that ListView calls getView() to draw the view for each item.To improve the UI rendering performance, the view returned by getView() should be recycled as much as possible. This is done by creating a ViewHolder class to hold the views.

When getView() is called, the view currently displayed to the user is also passed in, which is when it is saved in the ViewHolder and tagged. On subsequent calls to getView() with the same view, the tag identifies the view as already in the ViewHolder. In this case, the content can be changed on the existing view rather than create a new one.

The main activity is shown in Listing 9.17, and the resulting view of diary entries in a ListView is shown in Figure 9.4.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment