Im having some trouble with my ArrayList, im working on an app for my restaurant, i got the AutoCompleteTextView with my dishes, and when i select one of them it puts into a list and shows with an Adapter, the problem shows when i try to put another dish to my list of order, im from Guatemala so my examples will be in Spanish, by example im adding a dish called "Hamburguesa de pollo" and it adds correctly to te ArrayList, but when i add a Dish called "Ravioles" it removes the "Hamburguesa de pollo" and shows me two items that says "Ravioles" like this.
Problem And if i add more items the las times erase the old ones and show me the same over the entire list.
This is my declaration above the onCreate method
ArrayList<HashMap<String,String>> list = new ArrayList<>();
This is the listener of the AutoCompleteTexView
textViewPlatos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
textPlatos=textViewPlatos.getText().toString();
getJSON3();
textViewPlatos.setText("");
}
});
This works whit an AsyncTask and goes to this method, that does the query to get de data, and then add the item to the list, and shows to te adapter.
private void mostrarOrden3(){
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
JSONObject jo = result.getJSONObject(result.length()-1);
String id = jo.getString(Config.TAG_ID_PLATOS);
String nombre = jo.getString(Config.TAG_NOMBRE_PLATOS);
String precio = jo.getString(Config.TAG_PRECIO_PLATOS);
String descripcion = jo.getString(Config.TAG_DESCRIPCION_PLATOS);
String nombrecategoria = jo.getString(Config.TAG_NOMBRECATEGORIA_PLATOS);
comandas.put(Config.TAG_ID_PLATOS,id);
comandas.put(Config.TAG_NOMBRE_PLATOS,nombre);
comandas.put(Config.TAG_PRECIO_PLATOS,precio);
comandas.put(Config.TAG_DESCRIPCION_PLATOS,descripcion);
comandas.put(Config.TAG_NOMBRECATEGORIA_PLATOS,nombrecategoria);
list.add(comandas);
// }
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
NuevaOrdenActivity.this, list, R.layout.list_item_platos,
new String[]{Config.TAG_NOMBRE_PLATOS},
new int[]{ R.id.name});
listView.setAdapter(adapter);
}
I dont really know when the code erase the names and replaces all of them with the new item. I made a Debug and the items in list is really overwrited, over and over again, to the end it has a list of the same last items, sorry for my english, and thanks for helping me.