Loading images from server in to Android Grid view

In this tutorial, we will be looking at how to load images from server in to android grid view. Once you complete this tutorial, your application will look like this.


Lets call this application as a Movie Database. This will display list of movies and the name in a grid view.


1 . Creating Database

First of all lets create a database content_db. Create a new file named content_db.sql and copy and paste the below code and save it.

Now import the this file in to the database you have created.

2. Creating an API

Now you have the database ready, lets create an API to get all movies using PHP.

Copy the below code and save it in to file named content_db_getAllMovies.php in localhost location ( in my case its /var/www/html/). you can save it in your localhost location.

Make sure to change your database configuration as  per your database credentials, In the above file.

3. Creating an Android application

Now lets create a new android application called MovieDatabase, when you create an new application  in android studio it  will automatically create a new activity called MainActivity. You can  change it to anything you want, but i recommend to leave it as it is for this tutorial.

4. Creating Styles and Drawable

Copy and paste the below code inside /res/values/colors.xml file.

save and close it.

Now create a new file called grid_color_selector.xml inside /res/drawable/ folder and then copy and paste the below code.

save and close it.

5. Creating Layout files

Now create a new file called grid_item_layout.xml in your /res/layout/ folder and copy and paste the below code.

save and close it.

Now open your activity_main.xml which is located in /res/layout/  folder. open the file and copy and paste the below code.

Save and close it.

6. Java classes

create a new java file named GridViewAdapter.java inside your package and copy and paste the below code. make sure to change your package name.

save and close it.

Now create another new file called GridItem.java inside your package and then copy and paste the below code.

save and close it.

Now open you MainActivity.java class and make sure it looks like the below code.

save and close it.

7. Create a second activity

Now we need to create a new activity to be viewed when ever the movie is clicked. So lets create a new activity called DetailsActivity using your android studio.

8. Modify Manifest file.

This application need a internet connection to get data from the server, therefore it is necessary to add that permission to the manifest file. As shown in the below code.

9. Gradle Build

It is important to tell the gradle how to build the application. Note this application is using HttpClient package which is no more supported in android studio. Therefore its is very important how you set the build.gradle file.

Make sure your build.gradle file looks exactly as shown in the below code snippet.

make sure to set your applicationId. That’s it. compile the application and run it on your device or emulator. It should work fine.

10. Happy coding.

Feel free to tell me your comments and feedback’s below in the comments section. Thank you. 🙂

python script to check server status

Today lets write a simple script to chek the Apache server status using python.

create a simple file called server_check on your desktop, copy and paste the below code

Now lets execute and check.

open your terminal and navigate to the desktop and type the following command.

python check_service

then it will ask for a service name “Please enter service name :”

enter the service name eg: apache2 or mysql

you will see a output like this.

Screenshot from 2016-05-11 10-26-28

Today. i Upgraded the script, so that it can be more usable on server. This will support on Python 2.7+ only. checkout the sample script below.