The Restaurant Store
Step #9: Refresh Our List...................................................................
The reason the list does not update is because neither the Cursor nor the
CursorAdapter realize that the database contents have changed when we
save our restaurant. To resolve this, add model.requery(); immediately after
the call to insert() in the onSave object in LunchList. This causes the Cursor
to reload its contents from the database, which in turn will cause the
CursorAdapter to redisplay the list.
Rebuild and reinstall the application and try it out. You should have all the
functionality you had before, with the added benefit of restaurants living
from run to run of LunchList.
Here is an implementation of LunchList that incorporates all of the changes
shown in this tutorial:
package apt.tutorial;
import android.app.TabActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
public class LunchList extends TabActivity {
Cursor model=null;
RestaurantAdapter adapter=null;
EditText name=null;
EditText address=null;
EditText notes=null;
RadioGroup types=null;
RestaurantHelper helper=null;
@Override
public void onCreate(Bundle savedInstanceState) {