Android Programming Tutorials

(Romina) #1
The Restaurant Store

}

}

Step #8: Clean Up Lingering ArrayList References...........................


Since we changed our model in LunchList from an ArrayList to a Cursor,


anything that still assumes an ArrayList will not work.


Notably, the onListClick listener object tries to obtain a restaurant from the


ArrayList. Now, we need to move the Cursor to the appropriate position and


get a restaurant from that. So, modify onListClick to use the Cursor and the


property getter methods on RestaurantHelper instead:


private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position,
long id) {
model.moveToPosition(position);
name.setText(helper.getName(model));
address.setText(helper.getAddress(model));
notes.setText(helper.getNotes(model));

if (helper.getType(model).equals("sit_down")) {
types.check(R.id.sit_down);
}
else if (helper.getType(model).equals("take_out")) {
types.check(R.id.take_out);
}
else {
types.check(R.id.delivery);
}

getTabHost().setCurrentTab( 1 );
}
};

At this point, you can recompile and reinstall your application. If you try


using it, it will launch and you can save restaurants to the database.


However, you will find that the list of restaurants will not update unless you


exit and restart the LunchList activity.


101
Free download pdf