I need to populate a bank like this:
hashmap , but I can only use a key for a value, I could do with multiple values, or some other way I can do this without usingMilk 50 kcal 20 proteins 120 carbo etc
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);