Search code examples
androidsqlitearraylistandroid-recyclerviewadapter

SQLite Database - List all data from database with RecyclerView/adapter


i want to list all my stored data on database and show it on using a recycler view/adapter. Can anyone help me about this.

-i have a class of getter and setter(PWClass)

Here are some of my codes:

This is the time i am storing some data on class and add it on list but it is only a sample.

PWClass pwc = new PWClass("Facebook", "Action & Adventure", "2015");
    pwList.add(pwc);

    pwc = new PWClass("Instagram", "Action & Adventure", "2015");
    pwList.add(pwc);

    mAdapter.notifyDataSetChanged();

My problem is how can i combine the code above and calling a query on database to display datas like:

//i declare on top
private List<PWClass> pwList = new ArrayList<>();
private RecyclerView recyclerView;
private PWAdapter mAdapter;
Database controller;

//and from a method below
pwList.add(controller.add_pw());//adding on list array by calling my db method

Should i use some for/while loops/arrays? I am thinking the code above but i know its wrong. Do you get my point?

Please help so i can understand more, i appreciate your suggestions thanks!


Solution

  • read this post, you will get clear idea on Sqlite database. check this out