I am busy with a read-only book reader app that has one database and 3 tables. One table called chapters where the chapters have names, one table called subchapters where the chapters are numbers, and one table called entries which is the text content of the subchapters table. Each entry will have a number too for better organizatio.
chapters table has two columns: id, and name
subchapters table has two columns: id, and number
entries table has two columns: id, and text
I have generated the rawquery to pull a random text entry from the entries table on activity start and it works fine. However, I need two things:
When the random text displays on the activity screen in the view, I need it to give not just the text but the chapter name and the subchapter number as well.
When that view is clicked, I need it to take the user to the subchapter that this text came from where the user can then read and/or navigate, etc..
Problem I am having is that I need the app to be able to know which chapter and subchapter and entry that random text entry came from so it can display it and then take the user there on click.
I know it has to with JOIN and I have watched many tutorials and read many posts on here but I haven't seen anything like what I am talking about yet or I am just not understanding it seeing other unrelated examples.
This is my current rawQuery to get the random text entry:
public List<String> getRandomTextEntry() {
List<String> list = new ArrayList<>();
Cursor cursor = database.rawQuery("SELECT * FROM entries ORDER BY
RANDOM() LIMIT 1", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
list.add(cursor.getString(1));
cursor.moveToNext();
}
cursor.close();
return list;
}
Any help with this is greatly appreciated.