I cant seem to find any solutions to this problem on the internet. basically im working on an app that lets the user create workouts and view them and I’m struggling with the view part.
My database is all set up with user input using the fields exercise, sets and reps, the user creates a workout and the contents of the table used to build it are copied to a new one and the table is cleared to take in new input.
I want to create a recycler view using the table names, pass the selected item name to the next fragment and use the users selection to determine what data will be shown in the next recycler view.
Is this possible and if so please show me how, I’m supposed to have this app ready in a couple of days for an assignment
any help would be appreciated, thanks – Ian
2
Answers
It is possible.
Here’s a working demo that shows how.
First the class that extends SQLiteOPenHelper, as is typically used, namely DatabaseHelper in this example:-
The activity that will be called MainActivity2 being passed a unique identifier of the clicked item via an Intent Extra :-
An Adapter TheAdapter etc for the RecyclerView, including Item Click and Item Long Click listeners. Clicking an item Toasts details. Long clicking starts the second activity which displays the clicked item:-
Finally the first/initial activity MainActivity :-
When run:-
When an Item (e.g. A10 (whos’ id is 11)) is Long clicked :-
Clicking DONE returns to the first activity.
To clairfy, you would like to make list of the list?
Use one to many relationship or map using room.
I have done such implementation days ago feel free to ask.
https://developer.android.com/training/data-storage/room/relationships?fbclid=IwAR3P_rK8OeOpBpP9jgbL8FqxEKPXPvOaFwFiCMy4pIpblg_aF_9QloavHpM
https://developer.android.com/training/data-storage/room/relationships?fbclid=IwAR22XINRNxTs3b_KOleeYwjGuIwjUA90S3tvpMWkf1dKYjvDDo5qWAbLfoE
To get previous ID or name just use simple Bundle of position(or ID) of specific element from first recyclerview and use it in the second to display the right data.