Q:

listview - my new inserted data is replacing earlier data

I am beginner android developer and this is my first project. I have a listview on EntryTO.java to show data order from selected listview on ViewData.java. i use button to show ViewData,java. this is the code when i choose selected item from ViewData.java
ListView lv = (ListView) findViewById(android.R.id.list);
          lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
          @Override
          public void onItemClick(final AdapterView<?> adapter, View v, int pos, final long id) {
          final Dialog dialog = new Dialog(ViewData.this);
          dialog.setContentView(R.layout.dialog_view);
          dialog.setTitle("Masukkan Qty");
          dialog.show();
          final product b = (product) getListAdapter().getItem(pos);
          edtqty = (EditText) dialog.findViewById(R.id.edtqty);
          buttonok = (Button) dialog.findViewById(R.id.buttonok);
          buttonok.setOnClickListener(new OnClickListener(){
              @Override
              public void onClick(View v) {
              switchToEdit(b.getId());
              dialog.dismiss();
                   };
             });
          }
      });
  }
  public void switchToEdit(long id){
      product b = dataSource.getproduct(id);
      Intent i = new Intent(this, EntryTO.class);
      Bundle bun = new Bundle();

      bun.putLong("id", b.getId());
      bun.putString("brand", b.getbrand());
      bun.putString("qty",edtqty.getText().toString());
      i.putExtras(bun);
      finale();
      startActivity(i);
  }

And this is the code when i try to display on EntryTO.java
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.entry_to);
      dataSource = new DBDataSource(this);
      dataSource.open();
      mylist = new ArrayList<HashMap<String, String>>();
      Bundle bun = null;
      try{
          bun = EntryTO.this.getIntent().getExtras();
          id = bun.getLong("id");
          brand = bun.getString("brand");
          qty = bun.getString("qty");
          map1 = new HashMap<String, String>();
          if(map1.isEmpty()){
             map1.put("one", brand);
             map1.put("two", qty); 
             mylist.add(map1); 
          }else{
              int j=mylist.lastIndexOf(map1);
              map1.put("one", brand);
              map1.put("two", qty); 
              mylist.add(j,map1); 
          }
          try {
              adapter = new SimpleAdapter(EntryTO.this, mylist, R.layout.item_to,
                        new String[] {"one", "two" },
                        new int[] {R.id.edtbrandto, R.id.edtqtyto });
              setListAdapter(adapter);
          }catch (Exception e) {Toast.makeText(EntryTO.this, "Ada Error Exception", Toast.LENGTH_LONG).show();}
      }catch(NullPointerException e){}}

I try to use loop before. When I insert first order there's no problem. But when I try to insert second order, the second replaced the first order. It caused when i click button that shown ViewData.java, index of arraylist become 0 again. Now I try to check index of arraylist(mylist) with if function. If mylist.isEmpty insert data order, but when mylist is not empty get the index of latest data order and insert new data after that. The problem is, second data still replaced first data. How do i fix them?

A:

i found that answer from @ling.s was right. but it need some finishing touched. i try to make Globals.java. this is the code 
public class Globals {
public static ArrayList<HashMap<String, String>> mylist;

}
on EntryTO.java we just call mylist from Globals.java
if (Globals.mylist == null)
          Globals.mylist = new ArrayList<HashMap<String, String>>();
      Bundle bun = null;
      try{
          bun = EntryTO.this.getIntent().getExtras();
          id = bun.getLong("id");
          brand = bun.getString("brand");
          qty = bun.getString("qty");
          map1 = new HashMap<String, String>();
          if (Globals.mylist.size() == 0) {
              map1.put("one", brand);
              map1.put("two", qty); 
              Globals.mylist.add(map1);
          }else {
              int j=Globals.mylist.size();
              map1.put("one", brand);
              map1.put("two", qty); 
              Globals.mylist.add(j,map1);
          }
          try {
              adapter = new SimpleAdapter(EntryTO.this, Globals.mylist, R.layout.item_to,
                        new String[] {"one", "two" },
                        new int[] {R.id.edtbrandto, R.id.edtqtyto });
              setListAdapter(adapter);
          }catch (Exception e) {Toast.makeText(EntryTO.this, "Ada Error Exception", Toast.LENGTH_LONG).show();}
      }catch(NullPointerException e){}

its work.

