Listing 920 srccomcookbookdatastoragetesterData StorageTesterjava

package com.cookbook.datastorage_tester;

import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri;

import android.os.Bundle; import android.widget.TextView;

public class DataStorageTester extends Activity { TextView tv;

^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); setContentView(R.layout.main); tv = (TextView) findViewByld(R.id.output);

String myUri = "content://com.cookbook.datastorage/diaries"; Uri CONTENT_URI = Uri.parse(myUri);

//get ContentResolver instance

ContentResolver crInstance = getContentResolver(); Cursor c = crInstance.query(CONTENT_URI, null, null, null, null); startManagingCursor(c); StringBuilder sb = new StringBuilder(); if(c.moveToFirst()){ do{

sb.append(c.getString(1)).append("\n"); }while(c.moveToNext());

tv.setText(sb.toString());

Inside the main.xml layout file, an ID needs to be added for the TextView output, as shown in Listing 9.21.

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