1
I need to fill a bank like this:
Milk 50 kcal 20 proteins 120 Carbo etc.
I got to do with hashmap, but I can only use one key for a value, it would have to do with various values, or another way that can do it without being using HashMap
?
Map<String, Integer> mapalimentos = new HashMap<>();
mapalimentos.put("Maçã",60);
mapalimentos.put("Melancia",75);
mapalimentos.put("Banana",45);
//Log.d(TAG, "addalimentosbanco: adicionou");
for (final Map.Entry<String,Integer> entry : mapalimentos.entrySet()) {
//Log.d(TAG, "addalimentosbanco: Nome: " + entry.getKey() +" Calorias: "+ entry.getValue());
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Alimento alimento = realm.createObject(Alimento.class);
alimento.setNome(entry.getKey());
alimento.setCalorias(entry.getValue());
}
});
}
RealmResults<Alimento> results = realm.where(Alimento.class).findAll();
Log.d(TAG, "addalimentosbanco: Result: " + results);