Android Feed Example using PHP, MySQL and Volley

Again because of so many queries I am writing this android feed example tutorial. Recently I published Android Custom ListView with Images using RecyclerView and Volley. And in feedback many people asked that how to add more item on …

android feed example

Again because of so many queries I am writing this android feed example tutorial. Recently I published Android Custom ListView with Images using RecyclerView and VolleyAnd in feedback many people asked that how to add more item on scroll to the list.

If you are having about 1000 or more items then downloading it once from the server would take a lots of time. And downloading all items at once is not a good idea.

That is why we should create a feed. So in this tutorial we will display some items and on scroll the items will be downloaded and added.

Android Feed – Video

You can see this video to know what actually we will be creating in this tutorial.


Now if you want to learn how to create this then lets begin our project.

Creating Server Side Database and Scripts for our Android Feed

  • Data will come from server. And for this demonstration I am using Hostinger’s free hosting as my server.
  • The first thing you need is a database from where you will fetch the data.
  • This is my database you can create the same database or you can also change your database according to your need.
android feed database
Android Feed – Database
  • As you can see I have 9 records in my table. I will show 3 records at once and when will user reach bottom by scrolling I will load 3 more records.
  • Now the first thing we need is a script to connect to the database. Create a script named dbConnect.php and write the following code.

  • No need to explain the above given code. We have used it in almost every tutorial I published.
  • Now we will create the main script that will give us the data for our feed. Create a new script feed.php and write the following code.

  • While executing this script I have to pass a get variable. So for my case the URL is

http://www.simplifiedcoding.16mb.com/feed/feed.php?page=1

  • If you would go to the above URL you will get a JSON string as follows.

  • We will change the page=2, page=3 to get the next items. If you would go to the above URL you will get 3 values for our android feed. You can also use my URL for this project. But it would be good if you create your own.
  • Now we will move ahead to android part.

Creating an Android Feed Project

  • Create a new android project in android studio. I have named this android feed project as MyFeed.
  • Now the first thing you should do is add the following dependencies to your build.gradle file and sync the project.

  • So here we have added volley, recyclerview and cardview. Now add internet permission to your manifest file.

  • First we will create a class to declare some important constants. So create a class named Config.java and write the following code.

  • To load the images I am using NetworkImageView. And for this we need to create a Custom Volley Request. So we will use the same code we used in  Google Login Tutorial to Load Profile Picture.
  • Create a new class named CustomVolleyRequest.java and write the following code.

  • Inside activity_main.xml create a RecyclerView and a ProgressBar to show our android feed.

  • Now we need to create layout for our list. The list I have created looks like
android feed
Android Feed
  • For our list we need to create the above layout. So inside the layout folder create a .xml file named superheroes_list.xml and write the following code to create the above given layout.

  • Now to store the list items we will create a class. So create a class named SuperHero.java and write the following code.

  • To display the items in RecyclerView we need an adapter. So create one more class named CardAdapter.java and write the following code.

  • Finally come to MainActivity.java and write the following code.

  • Now run your application and you will see the following output.
android feed
Android Feed
  • Bingo! Our android feed application is working fine. If you are having troubles or getting errors; you can get my project from GitHub Repository from below.

[sociallocker id=1372] Get Android Feed Example from GitHub [/sociallocker]

So thats all for this android feed tutorial friends. Please support us and give your feedback with your comments. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x