Display data in RecyclerView from MySQL Database in Android Studio using The Library Volley - Mr Brohid
Hello Guys, Welcome again on Mr Brohid 's blog for this time, I want to share the knowledge of Display Data in RecyclerView from the MySQL Database on Android Studio using The Library Volley, in this article you can learn about how to display data from the database to your android application with RecyclerView.
Below are some data from the database that we will display on the recyclerview.
Below are some data from the database that we will display on the recyclerview.
Before we start coding on android studio we first create the php process to display data on the android studio. Copy the code below after that, create a folder on your xampp or server you and save it with the name getdata.php
OK, after we make the php process, we continue to make the process on the Android android, let's go ...
1. Add Library RecyclerView and Library
Volley
For this first process, we will add a volley library to your module app, This module app works for the process of running Android and put what library we will use to create an Android application.
Ok, we add the library Volley and library Recyclerview in dependencies, Like the example below
Example :
Ok, we add the library Volley and library Recyclerview in dependencies, Like the example below
2. Make Layout View
This second process we will create a
layout view on the application to display data in the recyclerview.
A. Layout for RecyclerView
For the design of the display you can design according to your wishes and
here I will give a simple design example so you can easily understand it.
Example layout design recyclerview :
B. Layout for List Item RecyclerView
After you create a layout for recyclerview, please create a new layout and
give the name custom_list.xml. How to add the custome_list.xml file in a
way. right-click on the directory layout-> New-> Layout Resouce
File and give the file name
with custom_list after that OK.
After successfully,
please design your layout according to your wishes, or you can copy what I
made, for example below:
Example list item recyclerview:
3. The Process of Displaying Data in
RecyclerView
This
third process we will make the process to display data from the MySQL database
to the recyclerview. This process has several stages that we must make, which
include:
I.
Make
Class Model
In
this first stage we will create a new Model class, namely the ModelData name.
This ModelData functions to create data variables, so that it is easier for us
to send data to adapters or other processes,
Example:
II.
Make
Class Adapter Process
After creating a Data Model, we will
create a new class with the name AdapterProcess.
This AdapterProcess works for the process of
displaying data from the database to the recyclerview.
Example :
III.
Make
Class Controller Volley
In this third stage we will create a controller class,
this controller to set the volley.
Source Code :
IV.
Get
Data use Volley in RecyclerView
In this fourth stage, we will make the process of
displaying data with a library volley. We put this process in
MainActivity.java. please see the process code below.
Source code :
This fourth process we will arrange or add some code on the Android Manifest.
Add uses-permission android: name = "android.permission.INTERNET" in the manifest
And add android:name for application and change controller a your make.
After all finish, please run on your android device, good luck.
So, from this article, I hope it will be useful and can help you, don't forget to read other articles, thank you: D
No comments:
Post a Comment