Android Server Client Tutorial With Volley And PHP,MYSQL Database,RecyclerView

By | January 14, 2018

We are going to create an app in android that fetches data stored from mysql  database using PHP and display in RecyclerView.This will sample news application which can show images and title of news and when clicked it reveals full details. as shown :Before we continue make sure you add the following libraries in build.gradle(Module App).


the above libraries can change according to your specific setup.

We are going to jump directly to code first creating Adapter class which will responsible for inflating ReclerViews  with list_items view

create package called adapters and inside it create CardAdapter class which extends Recycler.Adapter copy the following code in your CardAdapter class.


The above CardAdapter class has three main methods onCreateViewHolder which  inflates the layout to main parent of the RecyclerView.

onBindViewHolder takes each views of the all_news.xml and set the values from AllNewsData class which contains setters and getters methods for each individual views.

Another important point to note is the use of Glide library to load images to the view.

CardView has listeners to click event to take user to the next Activity AllContent class passing the values along as Intents.

We will create item view to be populated in each RecyclerView.Create the following xml resource file all_news.xml copy the following codes


Next class we are going to create is AllNewsData class which has setters  and getter methods to create data.

Create new package called config and inside it create class called “AllNewsData” and copy the following codes.


next we go to “MainActivity” class and in activity_main.xml add the following xml codes for the RecyclerView


In the MainActivity add the following codes to load data from database using volley from the PHP,MYSQL api.


Create package called config inside it create “Config” class and add the following codes.


Now that we have completed the Android part we should create our PHP API to fetch json data from mysql to display volley
In our serverside let create code for database connections “conn.php”;

create main API file inside your domain name it “fetch_data.php” this is the file sending request to volley from android.

Now run your code but first ensure you haa some data to display from database remember to add images absolute path in the database.

Thanks for following through with our tutorials this is just for learning purposes.

Leave a Reply

Your email address will not be published. Required fields are marked *