Reputation: 1720
I've been trying to prepare custom Views
to display SQLite database entries during a whole week without success.
I already tried the default list and Room Persistence Library approaches and even considered a JSON/GSON alternative, but to populate lists within lists with basic text strings seemed to be the easiest attempt meanwhile.
Basically, now I'm trying to mix two samples at once:
I've been able to add data from my database and to mix them up to some extent, but I ain't getting how to connect the database fields to the custom Views
on both levels of the list.
After I reached the ExpandableListView
on the MainActivity.java
, I got lost and I think the code may have some duplicated methods, maybe a confusion between dataAdapter
and the use of listAdapter
and the HashMap<String, List<String>>()
is probably wrong, but I don't have a clue about how to solve issues like these as of now, so, I ask for some help please to handle this situation.
Upvotes: 0
Views: 214
Reputation: 1720
Thanks to psikink support, I've been able to find a workaround for this issue.
Actually, during a whole week I've been looking for approaches over simple samples of ListViews
and ExpandableListView
with custom adapters, but as soon as I was able to catch the mindset of the advices provided, it was way easier to deal with this situation.
The turning point was to know about SimpleCursorTreeAdapter
and to pay more attention to SQLiteAssetHelper
methodology.
As soon as the code is ready, I'll upload it to my GitHub profile and I'll try to bring it here as well if possible.
As of now, this piece of code might be helpful, I guess.
Thanks Stack Overflow and psikink for the help!
Upvotes: 1
Reputation: 1720
For those who are trying to fetch data from a prepopulated SQLite database into an ExpandableListView
, you can simply use this sample code I created after asking this question here and there.
You'd just need to replace the database in this project by yours and refactor the respective fields to match your database name, table and items so as it fits your needs.
Basically, with a SimpleCursorTreeAdapter
, you'll be able to select two levels of data (group and child) from your database and SQLiteAssetHelper
will let you to load it from a preexisting file put inside the assets folder (/app/src/main/assets/databases/).
Upvotes: 0