In my android application i have 2 activities(act1,act2).in act1 i have a gridview and some data and when click to one item it will start the act2.in act2 i have a multi column listview and some data and when i press a button the data can add to list.the problem is when i back to act1 and select another item from gridview and the act2 again starts and my listview becomes empty(because the listview adapter is in act2 oncreate method).but i also need the previous data in list.if there is any idea to save or keep the listview data between activities.or any common method or class can be used to insert items to listview.
act1(MenuActivity)
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// to show a message box with particular name
//Toast.makeText(getApplicationContext(),((TextView) v.findViewById(R.id.VegName)).getText(), Toast.LENGTH_SHORT).show();
TextView Name=(TextView) v.findViewById(R.id.VegName);
TextView Price=(TextView) v.findViewById(R.id.VegPrice);
Intent i = new Intent(MenuActivity.this, AddOrderActivity.class);
i.putExtra("Name", Name.getText().toString());
i.putExtra("Price", Price.getText().toString());
startActivity(i);
}
});
act2(AddOrderActivity)
public class AddOrderActivity extends Activity implements View.OnClickListener
{
private ListView list;
private ArrayList<HashMap<String, String>> mylist;
private HashMap<String, String> map;
SimpleAdapter mSchedule;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activityaddorder);
Button btnAddItem = (Button) findViewById(R.id.btnAddItem);
btnAddItem.setOnClickListener(this);
list = (ListView) findViewById(R.id.listOrders);
mylist = new ArrayList<HashMap<String, String>>();
// used to show the heading of listview
map = new HashMap<String, String>();
map.put("txtItem", "Item");
map.put("txtQuantity", "Quantity");
map.put("txtTotal", "Total");
mylist.add(map);
mSchedule = new SimpleAdapter(AddOrderActivity.this, mylist, R.layout.listview_row,
new String[] { "txtItem", "txtQuantity", "txtTotal" }, new int[] {
R.id.txtItem, R.id.txtQuantity, R.id.txtTotal });
list.setAdapter(mSchedule);
}
@Override
//i want to add new row on this button click
public void onClick(View v) {
map.put("txtItem", "1");
map.put("txtQuantity", "2");
map.put("txtTotal", "2");
mylist.add(map);
mSchedule.notifyDataSetChanged();
}
}