且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQLite ListView启动新活动的意图

更新时间:2022-12-19 21:18:34

到目前为止,书籍活动会显示书籍名称,但是当我单击它时,它只会显示白屏...

So far, the book activity displays the book names, but when I click on it, it only displays a white screen...

我想我可能会在活动将所选信息发送到新活动以打开新列表视图的方式上弄乱了?该代码应如何显示?

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?

您可能想通过一本书获得这些章节,是吗?

You probably want to get the chapters by a certain book, yes?

所以,这样做

//Get book id
Intent i = getIntent();
book_id = i.getStringExtra("book_id");

然后使用该ID以获取章节的方式查询数据库

Then use that ID to query the database in a way that gets the chapters

//Get bible list in db when db exists
chapterList = DBHelperChapter.getListChapter(book_id);

//Init adapter
chapterAdapter = new customAdapterChaptertext (this, chapterList);

//Set adapter for listview
listviewChapter.setAdapter(chapterAdapter);

DBHelperChapter.getListChapter(book_id)可以返回此查询结果的位置

Where DBHelperChapter.getListChapter(book_id) could return the results of this query

mDatabase.rawQuery("SELECT * FROM table_chapter WHERE id_of_book = " + book_id);

旁注:由于您使用的是SQLite数据库,因此我建议尝试尝试使用CursorAdapter而不是ArrayAdapter来加载ListView

Sidenote: since you are using a SQLite database, I may suggest trying to look into using a CursorAdapter rather than an ArrayAdapter for loading a ListView