After countless hours of watching YouTube videos and tutorials, and reading up on info and advice, I've come to the conclusion that doing a bible app by using a SQLite database is the way to go.
I've got no knowledge of coding whatsoever and just by taking bits and pieces of tutorial code and advice from someone I've got this far, so please be specific when answering.
I've now created 3x tables.
table_book, table_chapter, and table_verse.
The tables are in one database.
The database gets installed with oncreate when the first Activity is clicked to open.
- table_book has 2x columns _id, book_name
- table_chapter has 3x columns, _id, id_of_book, chapter_number
- table_verse has 4x columns, _id, id_of_chapter, verse_number, verse_text
Furthermore,
- I've got 3x Activities, 1 for each table
- I've got 3x DBClasses, 1 for each table
- I've got 3x DBHandlers, 1 for each table
- I've got 3x Adapters, 1 for each table
The idea is that when you open the app and call the class to open the bible, it opens the book class and has a ListView, in the listview is all the bible books, when clicked, it should open the chapter activity and in its ListView display all the book's chapters, when selecting a chapter it should open the verse Activity and in its ListView display all the verses.
So far, the book Activity displays the book names, but when I click on it, it only displays a white screen...
Nothing shows errors in the logcat.
I think I might be messing something up in the way the Activity sends the selected info to the new Activity to open the new ListView?
How should this code look like?
Currently it's like this in the book class:
//Get bible list in db when db exists
DBClassBibledbBookList= DBHelperBook.getListBible();
//Init adapter
adapter_customAdapterBooktext = new customAdapterBooktext(this, DBClassBibledbBookList);
//Set adapter for listview
listviewBible.setAdapter(adapter_customAdapterBooktext);
@Override
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){
//on selecting a book
//BookActivity will be launched to show chapters inside
Intent bookid = new Intent (getApplicationContext(), ChapterActivity.class);
//send book_id to ChapterActivity to get chapters under that book
String book_id = ((TextView)view.findViewById(R.id.book_id)).getText().toString();
bookid.putExtra("book_id", book_id);
startActivity(bookid );
}
}
);
And in the chapter Activity:
//Get bible list in db when db exists
DBClassBibledbChapterList = DBHelperChapter.getListChapter();
//Init adapter
adapter_customAdapterChaptertext = new customAdapterChaptertext (this,DBClassBibledbChapterList );
//Set adapter for listview
listviewChapter.setAdapter(customAdapterChaptertext );
//Get book id
Intent i = getIntent();
book_id = i.getStringExtra("book_id");
//hashmap for listview
ChapterList = new ArrayList<HashMap<String, String>>();
listviewChapter.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener(){
@Override
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){
//on selecting chapter get verse text
Intent chapterid = new Intent(getApplicationContext(),BibleActivityVerse.class);
//to get verse both book_id and chapter_id is needed
String book_id = ((TextView) view.findViewById(R.id.book_id)).getText().toString();
String chapter_id = ((TextView)view.findViewById(R.id.chapter_id)).getText().toString();
chapterid.putExtra("book_id", book_id);
chapterid.putExtra("chapter_id", chapter_id);
startActivity(chapterid);
}
});
The DBClass:
public List<DBClassBibledbChapter> getListChapter(){
DBClassBibledbChapter DBClassBibledbChapter = null;
List<DBClassBibledbChapter> DBClassBibledbChapterList = new ArrayList<>();
opendatabase();
Cursor cursor = mDatabase.rawQuery("SELECT * FROM table_chapter", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()){
DBClassBibledbChapter = new DBClassBibledbChapter (cursor.getInt(0), cursor.getInt(1),cursor.getInt(2));
DBClassBibledbChapterList.add(DBClassBibledbChapter);
cursor.moveToNext();
}
cursor.close();
closeDatabase();
return DBClassBibledbChapterList;