Tuesday, December 27, 2016



Abre to Corazon..!!!!
Nice to See you Automator, in this opportunity I would like to share you about how to show the database data in your android using Recycleview. I think RecyclerView more effective then using manual listview. For my student of automation engineering you can directly download my sample project below the button to help you finish my final project. :)

Ok.. Let's we try to make it

Before you study more about internet data connection and database android, I advise you to study my older post here about HTTP request, and if you haven't software to edit the script you can download SUBLIME and NOTEPAD++.

1. Creating Server Side Database

  • Data will come from server. And for this demonstration I am using my Hostinger "to.ppns.ac.id"
  • 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.

Image 1. Database Server

  • As you can see I have 4 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 image.php and write the following code. Replace the HOST, USER,PASS, and DB corresponding with your database.



  • Save your php file in folder "file manager" and you can put it in your directory. for my directory i have been put it in "file manager"> "aplikasikomputer">image.php




Image 2. Directory File

  • Now executing this script I have to pass a get variable. So for my case the URL is
  • If you would go to the above URL you will get a JSON string as follows.
Image 3. Debugging JSON

  • 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.
2. Android Programming

  • 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.
  • For the update able usually use SDK 24 but in this tutorial i am still using SDK 23, so please adapted your dependencies like my code. 

  • 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. 
  • 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
Ok dear because this program will be so long, you can directly download my example project. But if you successfully done my tutorial you will see your project like, Until here if you still confused ucan study more about Http request in here:


Image 4. Result of the project

Ok, Download my projet here






2 komentar:

  1. addition sir,
    im a newbie and just find this solution want to share.
    for those anyone who want to practice this article but working on API level below 23, use addOnScrollListener(RecyclerView.OnScrollListener) which works on all API levels rather than setOnScrollChangeListener() that require API 23.
    thank you, great source for beginner

    ReplyDelete
    Replies
    1. Ok bagas... thanks alot for your good solution.

      Delete