Android MVVM Room LiveData Full CRUD App → Room Model Class – Camposha

Android MVVM Room LiveData Full CRUD App

Android Room LiveData CRUD

Room Model Class

In this lesson we create our model class. This lesson is part of our android mvvm livedata CRUD course with Room.
This model class we will create will have the following functionalities and characteristics:

  1. It will represent our data object, our Scientist object.
  2. From it Room will generate our Table Schema.
  3. It will be serializable thus we will be able to pass it around across activities.

Furthermore it will have the following fields:

  1. ID
  2. Name
  3. Galaxy
  4. Star
  5. DOB

Video Lesson

Full Code

Here is the full code:

package info.camposha.roomlivedatacrudapp.data.model;

import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import java.io.Serializable;

@Entity(tableName = "ScientistTB")
public class Scientist implements Serializable {

    @NonNull
    @PrimaryKey
    @ColumnInfo(name = "id")
    private String id;
    @ColumnInfo(name = "name")
    private String name;
    @ColumnInfo(name = "description")
    private String description;
    @ColumnInfo(name = "galaxy")
    private String galaxy;
    @ColumnInfo(name = "star")
    private String star;
    @ColumnInfo(name = "dob")
    private String dob;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public String getStar() {
        return star;
    }
    public void setStar(String star) {
        this.star = star;
    }
    public String getGalaxy() {
        return galaxy;
    }
    public void setGalaxy(String galaxy) {
        this.galaxy = galaxy;
    }
    public String getDob() {
        return dob;
    }
    public void setDob(String dob) {
        this.dob = dob;
    }
    @Override
    public String toString() {
        return getName();
    }
}
//end

Leave a Reply

Your email address will not be published. Required fields are marked *

Rating

Not enough ratings to display
X