-1

I have this android application which is basically an app that summarizes the 10th grade physics book, it has four units, each unit has multiple subjects, i want to to display large set of text data which lets the user to scroll down the page when a user presses on a subject, how can i store these static data on the application?, and what method to use?, should i use fragments to display the content?

Image 1 Image 2

Each unit has many subjects like this, i want to display a large set of text when a user click on something

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

how can i store these static data on the application?

To store the content you may use the SQLite database. The Room Persistence Library from Jetpack is a good way to start. It's an SQLite wrapper which is very easy to learn and much easy to use. This article will teach you about basic CRUD (Create, Read, Update and Delete) operation using Room.

should i use fragments to display the content?

It's up to the application requirement. One use case would be, when you have a common navigation bar, fragment would be a better option. You can find more case information on 'When to use fragments' from this answer.

@AJW

What if I already have a working SQLite database with a lot of custom CRUD queries. And the queries use Cursors. Should I convert all of the existing queries and replace them with new Room queries?

I haven't tried a complete migration yet, and not have too much experience with room. I tried some sample CRUD operations and it looks cool. It avoids so many boilerplate code that I used to write when using SQLiteOpenHelper, also it supports LiveData , which is another big advantage, helps you to get database updates automatically. Altogether, Room looks promising, and I believe it's the future. I would suggest you to do a sample project before converting all your sqlite queries to Room. This tutorial might help you to get started also the official docs are pretty good.

can I use the SQLite queries with Room?

Yes you can. Actually, Room needs the query to generate objects for us.

A typical SELECT query looks like below

@Query("SELECT * FROM users")
fun loadAllUsers(): List<User>

You can find more examples from the official docs

theapache64
  • 10,926
  • 9
  • 65
  • 108
  • Thank you so much, your answer really helped me clear my head. – loyal Turkman Jan 04 '19 at 16:08
  • @theapache64 What if I already have a working SQLite database with a lot of custom CRUD queries. And the queries use Cursors. Should I convert all of the existing queries and replace them with new Room queries? Or can I use the SQLite queries with Room? – AJW Jan 23 '19 at 17:40
  • @AJW As the answer for you question became lengthy, I've added the reply on answer. Please check the updated answer. – theapache64 Jan 24 '19 at 05:25