Guest User

Untitled

a guest
Nov 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Map<String, Integer> mapalimentos = new HashMap<>();
  2. mapalimentos.put("Maçã",60);
  3. mapalimentos.put("Melancia",75);
  4. mapalimentos.put("Banana",45);
  5.  
  6. //Log.d(TAG, "addalimentosbanco: adicionou");
  7.  
  8.  
  9. for (final Map.Entry<String,Integer> entry : mapalimentos.entrySet()) {
  10. //Log.d(TAG, "addalimentosbanco: Nome: " + entry.getKey() +" Calorias: "+ entry.getValue());
  11. realm.executeTransaction(new Realm.Transaction() {
  12. @Override
  13. public void execute(Realm realm) {
  14. Alimento alimento = realm.createObject(Alimento.class);
  15. alimento.setNome(entry.getKey());
  16. alimento.setCalorias(entry.getValue());
  17. }
  18. });
  19. }
  20. RealmResults<Alimento> results = realm.where(Alimento.class).findAll();
  21. Log.d(TAG, "addalimentosbanco: Result: " + results);
Add Comment
Please, Sign In to add comment