Android - Store Class Object into ArrayList or List
In this tutorial, we will change our model to be a list of restaurants, rather than just one. Then, we will add a ListView to view the available restaurants. This will be rather incomplete, in that we can only add a new restaurant, not edit or delete an existing one. We will cover those steps too in a later tutorial. Note : Please refer previous post before step on this tutorial Hold a List of Restaurants First, if we are going to have a list of restaurants in the UI, we need a list of restaurants as our model. So, in LunchList , change: Restaurant r=new Restaurant(); to List<Restaurant> model=new ArrayList<Restaurant>(); Note that you will need to import java.util.List and java.util.ArrayList as well. Save Restaurant Object to List All we need to do is add a local restaurant r variable, populate it, and add it to the list: private View.OnClickListener onSave=new View.OnClickListener() { public void onClick(View v) { Restaurant r=new Resta