RecyclerView with sqlite database android tutorial
The following gif is an overview of what we are about to build
First of all create a new project in android studio
now setup the following dependencies in your app level build.gradle file
Now setup all the assets like shown below
go to res >> drawable and create brown_border.xml,pedit.png,pdelete.png
brown_border.xml
Now go to res >> values >> colors.xml and add the following
Now go to res >> values >> strings.xml and add the following
Now create res >> menu >> menu_main.xml like this
Now create res >> layout and add the following
activity_main.xml add_contact_layout.xml contact_list_layout.xml
Now let us look into some java code
First of all create a helper class which extends SQLiteOpenHelper as shown below
SqliteDatabase.java
The above helper class provides methods to perform all the basic CRUD operations like add, update, delete etc.Now we should create a model class for the contacts object, it should be like
Contacts.java
Now we should create a recyclerview adapter for our recyclerview. It will include a Filter method which would be used to do search operations within our contacts list.
ContactAdapter.java
Below is the code for ContactViewHolder.java which is used in the above adapter class
Update your MainActivity.java file like shown below
With this, we have come to the end of this tutorial, now try running the app!
You may also check an advanced tutorial here >>
Android Recyclerview Tutorial with SQLite ROOM : using MVVM, Dagger 2
![]() |
| add, edit, delete, search contacts |
First of all create a new project in android studio
now setup the following dependencies in your app level build.gradle file
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
Now setup all the assets like shown below
go to res >> drawable and create brown_border.xml,pedit.png,pdelete.png
brown_border.xml
![]() |
| pedit.png(download) |
![]() |
| pdelete.png(download) |
Now go to res >> values >> colors.xml and add the following
Now go to res >> values >> strings.xml and add the following
Now create res >> menu >> menu_main.xml like this
Now create res >> layout and add the following
activity_main.xml add_contact_layout.xml contact_list_layout.xml
Now let us look into some java code
First of all create a helper class which extends SQLiteOpenHelper as shown below
SqliteDatabase.java
The above helper class provides methods to perform all the basic CRUD operations like add, update, delete etc.Now we should create a model class for the contacts object, it should be like
Contacts.java
Now we should create a recyclerview adapter for our recyclerview. It will include a Filter method which would be used to do search operations within our contacts list.
ContactAdapter.java
Below is the code for ContactViewHolder.java which is used in the above adapter class
Update your MainActivity.java file like shown below
With this, we have come to the end of this tutorial, now try running the app!
You may also check an advanced tutorial here >>
Android Recyclerview Tutorial with SQLite ROOM : using MVVM, Dagger 2



24 comments
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/com.chutiya.example-WyUxuvgeWlh6jQlcHfOkTQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.chutiya.example-WyUxuvgeWlh6jQlcHfOkTQ==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:827)
a…
frankly you are great !!!
on lines
//=========================================0 SQLdatabase
if(cursor.moveToFirst()) {
do {
int id = Integer.parseInt(cursor.getString(0));
//=========================================0
//=========================================1 Main_Activity
if(allContacts.size() > 0) {
contactsView.setVisibility(View.VISIBLE);
mAdapter = new HexTextAdapt(this, allContacts);
contactsView.setAdapter(mAdapter);
//=========================================1
W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
endBatchEdit on inactive InputConnection
please reply
It worked for me in many cases
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SearchView.setOnQueryTextListener(android.widget.SearchView$OnQueryTextListener)' on a null object reference
at com.example.recycl_sqlite.MainActivity.search(MainActivity.java:129)
at com.example.recycl_sqlite.MainActivity.onCreateOptionsMenu(MainActivity.java:122)
at android.app.Activity.onCreatePanelMenu(Activity.java:4119)
> Task :app:compileDebugJavaWithJavac
Note: //.....\DataAdapter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
public class DataAdapter extends RecyclerView.Adapter implements Filterable{
private Context context;
private ArrayList listData;
private ArrayList mArrayList;
private SqliteDatabase mDatabase;
public DataAdapter(Context context, ArrayList listData) {
this.context = context;
this.listData = listData;
this.mArrayList = listData;
mDatabase = new SqliteDatabase(context);
}
@Override
public DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_data_list_layout, parent, false);
return new DataViewHolder(view);
}
@Override
public void onBindViewHolder(DataViewHolder holder, int position) {
final Data data = listData.get(position);
holder.t…
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Account associated with identity was null
at zuv.a(PG:131)
at zuv.get(PG:78)
at zyq.a(PG:1)
at zxc.a(PG:4)
at fyf.run(Unknown Source:6)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at psm.run(PG:12)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.IllegalStateException: Account associated with identity was null
at fxj.a(Unknown Source:19)
a…