Home / Videos / Raum + ViewModel + LiveData + RecyclerView (MVVM) Teil 2 – ENTITY – Android Studio Tutorial

Raum + ViewModel + LiveData + RecyclerView (MVVM) Teil 2 – ENTITY – Android Studio Tutorial



In Teil 2 des Tutorials zu Architekturkomponenten werden wir ein neues Android Studio-Projekt einrichten, die Raum- und Lebenszyklusabhängigkeiten hinzufügen und dann unsere Note-Klasse erstellen.
Durch Annotieren dieser Java-Klasse mit @Entity können wir den gesamten erforderlichen Code zum Erstellen einer SQLite-Tabelle für dieses Objekt sowie Spalten für alle Felder generieren lassen. Mit @PrimaryKey und autoGenerate = true können wir eine ganzzahlige Membervariable in einen automatisch inkrementierenden Primärschlüssel umwandeln, mit dem wir jede Zeile in der Tabelle eindeutig identifizieren können. In der Vergangenheit mussten wir all dies in einem SQLiteOpenHelper mit einfachen SQL-Anweisungen ausführen.
Zuletzt erstellen wir einen Konstruktor, Getter und Setter, und dann kümmert sich Room zur Laufzeit um die Erstellung des gesamten Code für das Boilerplate. Wir können auch den Tabellennamen angeben, wenn er sich vom Klassennamen unterscheiden soll.
Es gibt einige weitere Anmerkungen und Einstellungen wie @Ignore und @ColumnInfo, über die Sie in der folgenden Dokumentation mehr erfahren können.

Sehen Sie sich die gesamte Wiedergabeliste an:

Beispielcode, Abhängigkeiten und Anweisungen:

AndroidX Refactoring-Tabelle:

Unternehmensdokumentation:

____________________
❗ Abonniere den Kanal:

⏯ Weitere Tutorials ansehen:

㊙ Hilf beim Übersetzen der Videos:

💚 Unterstütze den Inhalt:
 

💬 Am Discord-Chat teilnehmen:

🎧 Hörbücher und Podcasts für Programmierer:
 

👶 So fangen Sie mit der Android-Entwicklung an:
 

📣 Folgen Sie Coding in Flow in den sozialen Medien:

Facebook:

Instagram:

Twitter:

Blog:
  .

About AndroidWeltEditor

Check Also

Huawei gewinnt "Beste 5G Core Network Technologie" Auszeichnung beim 5G World Summit

Huawei # 5G Huawei gewinnt beim 5G World Summit die Auszeichnung “Beste 5G Core Network …

43 comments

  1. for entity class setter methods is very good approach than calling a constructor. what if you have 20 or more fields in a table. and you want to pass only some data to it.

  2. You should definitely put a link to these videos in your older videos where you explain the whole process of the OpenHelper classes and so on 😅 I first created my whole project with OpenHelper and now I am recreating it 😄 but it's nice to know the stuff we learned in the videos with the OpenHelper

  3. If your ide give an error about Manifest merger. Go your Manifest.xml and paste these:
    tools:replace="android:appComponentFactory"

    android:appComponentFactory="whateverString"

    to <application

    />

  4. Note that to use Androidx the targetSdkVersion has to be at least 28, this took me a while to figure out

  5. Great Video!!!. How Can I put one only entity for 6 tables? I just have on model class and the same model class (id, name, quantity) that'll used for six tables. How can I implment that?

  6. Once again this video is your usual exemplary standard of clear, accurate explanation – Thanks. The cherry on the top this time being that you even went to the trouble of future proofing the code by explaining what to do when Google made planned changes (which they now have).
    Florian, you really are the best!

  7. First, great video! Thank you very much. just one thing…why didn't you also generated setters for all the instances, is there a special reason? and shouldn't that be a problem with @Update?

  8. Why did we not create setter methods for title, description, and priority?

    Is it because the values of these attributes are dynamic and change with each iteration of their instance??

    Great tutorial by the way + love that sexy German accent! 🙂

  9. I love these videos! They are clear, thorough, comfortable to follow. I like to calm voice and the nice accent. Thanks a lot for your videos!

  10. Awesome, nice and simple description and illustrate each point … Thx man …

  11. Happy to be on your channel again. The video was very helpful. Thank you!

  12. great content sir 🙂 i didnt understand when you said that Room needs a constructor in order to re create.. can u please make this clear. Thank you

  13. Your videos are really good! You are very structured and have just the right amount of depth for a beginner. Thanks!

  14. can we use Room without using MVVM design pattern ? it seems all the tutorials on youtube using Room and MVVM tight together. can we use it in MVC ?

  15. I am getting compiler error

  16. Great video! Thank you for this but i'm not sure if i understood the roles of Getters/setters and constuctors. To be honest, your videos make more sense than google's documentation. You said that if id is not included then room cannot get it back from the database, thus we need a setter method for it. But what happens under the hood? If i call the dao's 'insert' or query 'Select *' does that mean that the constuctor and setters/getters are in play at the same time? i suppose that the constuctor would make an instance and then the set_id method would run afterwards and then get the object back?

  17. Florian is the best! thank you

  18. si,r give source code link please . i have face setter method problem error.

  19. As always very clear and informative.

  20. Can we create a dynamic table??
    For example , if we want to create a table by user.then is it possible??

  21. I had to laugh, I wrote an article about SQL open helper in 2011…
    I was just learning then so no laughing but that was hard stuff compared to now!!
    .http://auroraquestsoftware.blogspot.com/2011/07/how-to-upgrade-sqlite-in-android.html?m=1

  22. This series is a great series for those of use old people who need to move away from deprecated LoaderManager.LoaderCallbacks. I had put off learning Room + ViewModel + LiveData because I didn't have time to go through the cumbersome documentation. This series is easy to understand and it teaches you the WHY. Idefinately recommend it!

  23. @Coding in Flow for future students of this course:
    Build.gradle problems? Here is what I used and it worked for me fine:

    def lifecycle_version = "2.0.0"

    def room_version = "2.0.0"

    //Lifecycle components

    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-rc01"

    annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0-rc01"

    //Room components

    implementation "androidx.room:room-runtime:2.0.0-rc01"

    annotationProcessor "androidx.room:room-compiler-rc01"

    this takes into account the recent migration from the old implementations to the Androidx ones.

  24. Hi, I would really appreciate if you could help me… I have followed your series of videos regarding video room+viewmodel and I started creating an app using the same format, that will enable me to create a gym schedule. I have added an extra attribute to the Note class, Date (as a string) so that the user would be able to chose a date for the workout. At the moment I am trying to create a method that will set the workout on the main page (a different screen) depending on what date it is. For instance if the date was 18th June 2018, it would show the workout created for the 18th of June. However i am having some issues looping through the list and getting the information…could you please tell me how to do it. I'm new to programming. is there another way to contact you

  25. i love your explanation about android arch component.

  26. I didn't found what i need to use for dependencies. I think link is changed, can you help me ?

  27. "Error inflating class android.support.design.widget.CoordinatorLayout"

    I migrated to androidx and Im currently using
    'com.android.support:design:28.0.0' as implementation.
    also tried with
    'com.google.android.material:material:1.1.0-alpha07' and 'com.google.android.material:material:1.0.0-rc01' and yet nothing works.

    Ok the solution is updating the component tag at the activity_main XML file to
    <androidx.coordinatorlayout.widget.CoordinatorLayout>

    The easiest way to check if all your tags are up to date is:…., upon refactoring to androidx, just rewrite each name and the autocomplete brings the correct tag.

  28. can you give github link for the code?

  29. why we are adding setter only for id not all data member?

  30. hey can u add a date picker to your code to show where it has to go or send it to me

  31. Might be a bit late to ask, but what if I want to store an image in this database? What data type would be required and how would you implement it?

  32. Great playlist! Thanks for that amazing job you helped us a lot.
    I have a small problem with my app, in my ENTITY class I have a URI attribute, when compilng it says that Room can not add this to the data base and suggeste to use Type Converter. How can I convert a URI so that Room accept it?

  33. can we do entity inheritance in room?
    for example in here can I create another entity say suppose : courseNotes entity that inherits notes entity

  34. Hi Florian, can't thank you enough for adding these videos. Requesting you to please cover the case when the table contains custom class as a column (case when we use typeConverters). You really make things easier to understand. Thanks again!

  35. Those who are finding difficulties in adding dependencies on Gradle – please add below 4 lines –

    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.1"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
    //Room Data
    implementation "android.arch.persistence.room:runtime:1.1.1"
    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

  36. Hello awesome tutorial. Voice are crisp and clear all over the video. Eager to learn more from your upcoming tutorials.

Leave a Reply

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