Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.isaac.appet.HomeFragment;
- import android.graphics.Bitmap;
- import android.graphics.drawable.Drawable;
- import android.widget.ImageView;
- import java.io.Serializable;
- import io.realm.RealmList;
- import io.realm.RealmObject;
- import io.realm.annotations.PrimaryKey;
- public class Pets extends RealmObject implements Serializable {
- @PrimaryKey
- long id;
- public String petType;
- private String petName;
- private String petUrlImage;
- private RealmList<Alarms> alarms = new RealmList<>();
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getPetType() {
- return petType;
- }
- public void setPetType(String petType) {
- this.petType = petType;
- }
- public RealmList<Alarms> getAlarms() {
- return alarms;
- }
- public void setAlarms(RealmList<Alarms> alarms) {
- this.alarms = alarms;
- }
- public String getPetUrlImage() {
- return petUrlImage;
- }
- public void setPetUrlImage(String petUrlImage) {
- this.petUrlImage = petUrlImage;
- }
- public String getPetName() {
- return petName;
- }
- public void setPetName(String petName) {
- this.petName = petName;
- }
- }
- btnSaveAlarm.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- realm.beginTransaction();
- Alarms alarm = new Alarms();
- alarm.setTitle(etAlarmTitle.getText().toString());
- alarm.setTime(etAlarmTime.getText().toString());
- alarm.setDesc(etAlarmDesc.getText().toString());
- Number maxId = realm.where(Alarms.class).max("id");
- long nextID;
- if (maxId == null) {
- nextID = 1;
- } else {
- nextID = maxId.longValue() + 1;
- }
- alarm.setId(nextID);
- realm.copyToRealmOrUpdate(alarm);
- realm.commitTransaction();
- finish();
- }
- });
- adapter.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int position = adapter.getPositionFromView(v);
- Pets pressPet = pets.get(position);
- RealmResults<Alarms> results = realm.where(Alarms.class).findAll();
- alarms.clear();
- alarms.addAll(pressPet.getAlarms());
- adapterAlarms.notifyDataSetChanged();
- }
- });
- package com.isaac.appet.HomeFragment;
- import java.io.Serializable;
- import io.realm.RealmList;
- import io.realm.RealmObject;
- import io.realm.annotations.PrimaryKey;
- public class Alarms extends RealmObject implements Serializable {
- @PrimaryKey
- long id;
- RealmList<Pets> namePetAlarm;
- String title;
- String desc;
- String time;
- public long getId() { return id; }
- public void setId(long id) { this.id = id; }
- public RealmList<Pets> getNamePetAlarm() {
- return namePetAlarm;
- }
- public void setNamePetAlarm(RealmList<Pets> namePetAlarm) {
- this.namePetAlarm = namePetAlarm;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getDesc() {
- return desc;
- }
- public void setDesc(String desc) {
- this.desc = desc;
- }
- public String getTime() {
- return time;
- }
- public void setTime(String time) {
- this.time = time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement