Android MySQL – Select Multiple Columns and Fill Custom ListView
Android MySQL – Select Multiple Columns and Fill Custom ListView Tutorial
How to select multiple columns from mysql database and populate a custom listview with multiple textviews.
Overview
Welcome. In this class we are going to look at MySQL database. How to connect to MySQL, retrieve multiple columns and rows from a given database table and bind them to a custom ListView.
That ListView will have several fields, each representing a given record column from our mysql database table.
These fields will include:
ID.
Name.
Propellant.
Description.
Our application will have the following classes:
No.
Class
Description
1.
Spacecraft.java
Will represent our data object. We will be selecting spacecrafts from our mysql database.
2.
CustomAdapter.java
This is the adapter needed to adapt our data to our custom listview. It will also inflate the custom layout which will make up the ListView view items.
3.
Connector.java
This is the class responsibe for setting up our connection and returning a HttpURLConnection object.
4.
DataParser.java
This is the class responsible for parsing our JSON data and returning an ArrayList containing our data.
5.
Downloader.java
This is the class responsible for actually downloading our json data in a background thread via AsyncTask. The networking class used for this download is our HttpURLConnection.
6.
MainActivity.java
This is our main activity. It represents the overall user interface or screen.
Tools Used
These are the tools we used to create the project:
Here’s our PHP Code to select multiple columns data from our mysql database and return it in json format.
Am using Wamp: C:wampwwwandroidspacecraft_select.php.
<?php
$host='127.0.0.1';
$username='root';
$pwd='';
$db="spacecraftDB";
$con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect');
if(mysqli_connect_error($con))
{
echo "Failed to Connect to Database ".mysqli_connect_error();
}
$sql="SELECT * FROM spacecraftTB";
$result=mysqli_query($con,$sql);
if($result)
{
while($row=mysqli_fetch_array($result))
{
$flag[]=$row;
}
print(json_encode($flag));
}
mysqli_close($con);
?>
2. Setup
(a). Create Basic Activity Project
First create a new project in android studio. Go to File –> New Project.
(b). Project Structure
Here’s our project structure:
(c). Build.Gradle
Our app level(app folder) build.gradle.
AndroidStudio allows us to add our application dependencies right here using compile statements.
So we add our dependencies here. You may use later versions of the dependencies.
Android is normally written in Java programming language. Java classes are normally organized in packages. This class will have the com.tutorials.hp.mdmysqlselect.mDataObject package.
This class is a public class and represents a single spacecraft for us.
The class will have the following instance fields:
Id – spacecraft id.
Name – spacecraft name.
Propellant – spacecraft propellant.
description – spacecraft description.
We create the getters and setters of these instance fields.
package com.tutorials.hp.mdmysqlselect.mDataObject;
public class Spacecraft {
int id;
String name,propellant,description;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPropellant() {
return propellant;
}
public void setPropellant(String propellant) {
this.propellant = propellant;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
(b). CustomAdapter.java
This class will be deriving from android.widget.BaseAdapter. This class is public class.
This class will maintain a couple of instance fields:
LayoutInflater object to inflate our model.xml layout.
The constructor of this class will take in a Context object and an ArrayList of spacecrafts objects.
Then inside the Constructor we assign those objects to their respective class instance fields that we had defined.
this.c = c;
this.spacecrafts = spacecrafts;
We then initialiaze our LayoutInflater class: inflater= (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE) assigning to LayoutInflater class.
LayoutInflater instance will later allow us inflate our XML layout into view object.
After deriving from baseadapter, we will be forced to implement a couple of abstract methods.
These include :
getCount() – return the number of spacecrafts to bind to our ListView.
getItem()– get a single spacecraft object.
getView() – inflate the model.xml layout and return it as a view object.
This class is a public class with one static method.
This method is our connect(..) method. This method will take a string object we are calling urlAddress to represent the URL string to our server side PHP script that will allow us fetch data from mysql database.
This method will return us a java.net.HttpURLConnection.
We’ll have a try-catch block, catching two exceptions :
java.net.MalformedURLException – Raised when a malformed URL is encountered.
java.io.IOException – Raised when an IO(Input Output) error has occured.
First we attempt to instantiate a java.net.URL passing in our URL address. URL stands for Uniform Resouce Locator and points to a Resource in a the World Wide Web. In this case that resource will be our php script.
url.openConnection() will return us a URLConnection object which represents the connection to the remote object referred to by the URL.
We cast that URLConnection to HttpURLConnection. HttpURLConnection is a url connection which supports HTTP specific features. It works with the HTTP protocol.
con.setRequestMethod() will set the HTTP Request method that we support. These can be :
GET.
POST.
PUT.
DELETE.
HEAD.
OPTIONS.
We use GET since we are fetching data.
con.setReadTimeout() will specify the timeout for reading our resouce while con.setConnectTimeout() indicates the timeout for our connection.
con.setDoInput() indicates that our connection supports input of data.
Our MainActivity’s primary layout. Will get inflated into MainActivity user interface.
At the root we have android.support.design.widget.CoordinatorLayout.
This layout has the following responsibilities:
No.
Responsibility
1.
Define the AppbarLayout using android.support.design.widget.AppBarLayout tag.
2.
Define the ToolBar using the android.support.v7.widget.Toolbar tag.
3.
Define the FloatingActionButton using the android.support.design.widget.FloatingActionButton tag.
4.
Include the content_main.xml which will render our other views and widgets.
This is our custom Parser class. The class still extends android.os.AsyncTask.
This class will parse our JSON string and fill our listview.
It has the following roles:
No.
Responsibility
1.
Receive Context object,ListView and the downloaded data from Downloaded class.
2.
Define an arraylist to hold the downloaded data.
3.
Instantiate, show and dismiss the progress dialog.
4.
Parse the json string and populate our ArrayList. We do this in the background thread inside the doInbackground() method.
5.
Bind our arraylist to our ListView.
package com.tutorials.hp.mysqlselector;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Parser extends AsyncTask<Void,Integer,Integer> {
Context c;
ListView lv;
String data;
ArrayList<String> players=new ArrayList<>();
ProgressDialog pd;
public Parser(Context c, String data, ListView lv) {
this.c = c;
this.data = data;
this.lv = lv;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd=new ProgressDialog(c);
pd.setTitle("Parser");
pd.setMessage("Parsing ....Please wait");
pd.show();
}
@Override
protected Integer doInBackground(Void... params) {
return this.parse();
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
if(integer == 1)
{
//ADAPTER
ArrayAdapter<String> adapter=new ArrayAdapter<String>(c,android.R.layout.simple_list_item_1,players);
//ADAPT TO LISTVIEW
lv.setAdapter(adapter);
//LISTENET
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Snackbar.make(view,players.get(position),Snackbar.LENGTH_SHORT).show();;
}
});
}else
{
Toast.makeText(c,"Unable to Parse",Toast.LENGTH_SHORT).show();
}
pd.dismiss();
}
//PARSE RECEIVED DATA
private int parse()
{
try
{
//ADD THAT DATA TO JSON ARRAY FIRST
JSONArray ja=new JSONArray(data);
//CREATE JO OBJ TO HOLD A SINGLE ITEM
JSONObject jo=null;
players.clear();
//LOOP THRU ARRAY
for(int i=0;i<ja.length();i++)
{
jo=ja.getJSONObject(i);
//RETRIOEVE NAME
String name=jo.getString("Name");
//ADD IT TO OUR ARRAYLIST
players.add(name);
}
return 1;
} catch (JSONException e) {
e.printStackTrace();
}
return 0;
}
}
(c). MainActivity.java
Our public class that will be the launcher activity. It will derive from android.support.v7.app.AppCompatActivity.
This class the following responsibilities:
No.
Responsibility
1.
Allow itself to become an android activity component by
deriving from android.support.v7.app.AppCompatActivity.|
|2.|Listen to activity creation callbacks by overrding the onCreate() method.|
|3.|Invoke the onCreate() method of the parent Activity
class and tell it of a Bundle we’ve received. |
|4.|Inflate the activity_main.xml into a View object and set
it as the content view of this activity.|
|5.| Define our URL address. This URL address leads to ou PHP script|
|6.| Reference the android.support.v7.widget.Toolbar and set it to the SupportActionBar.|
|7.| Reference ListView from layout.|
|8.| Instantiate Downloader class. Pass in the URL addtess, ListView and Context.|
|9.| Execute the download operation.|
Android MySQL – ListView CheckBoxes – INSERT,SELECT,SHOW
This is an Android MySQ ListView with CheckBoxes tutorial. We want to see how to work with boolean text values. We save them into mysql and also retrieve them.
We want to see how to work with Android PHP MySQL and Boolean values and strings.
First we want to insert data to MySQL database.
The data shall be from a material edittext,a spinner and a checkbox.
The user types his favorite spacecraft name in the edittext.Then selects the spacecraft’s propellant from a spinner.
He then selects if the technology exists yet or not in the checkbox.
We shall actually be mapping integers to boolean and vice versa since MySQL doesn’t have a native boolean data type.
Our adapterview is ListView.It has checkboxes to hold boolean values from MySQL database.
Video Tutorial(ProgrammingWizards TV Channel)
Well we have a video tutorial as an alternative to this. If you prefer tutorials like this one then it would be good you subscribe to our YouTube channel.
Basically we have a TV for programming where do daily tutorials especially android.
Android MySQL ListView CheckBoxes Insert, Select Show Example
Let’s look at our example:
MySQL Table
Here’s our mysql table structure:
Project Structure
Here’s our project structure.
1. PHP Code
Here are our php code. Place them in the same folder.
Here are our gradle scripts in our build.gradle file(s).
(a). build.gradle(app)
Here’s our app levelbuild.gradle file. We have the dependencies DSL where we add our dependencies.
This file is called app level build.gradle since it’s located in the app folder of the project.
If you are using Android Studio version 3 and above use implementation keyword while if you are using a version less than 3 then still use the compile keyword.
Once you’ve modified this build.gradle file you have to sync your project. Android Studio will indeed prompt you to do so.
package com.tutorials.hp.mysqllistviewbool.mModel;
public class Spacecraft {
/*
INSTANCE FIELDS
*/
private int id;
private String name;
private String propellant;
private int technologyExists;
/*
GETTERS AND SETTERS
*/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPropellant() {
return propellant;
}
public void setPropellant(String propellant) {
this.propellant = propellant;
}
public int getTechnologyExists() {
return technologyExists;
}
public void setTechnologyExists(int technologyExists) {
this.technologyExists = technologyExists;
}
/*
TOSTRING
*/
@Override
public String toString() {
return name;
}
}
(b). MySQLClient.java
Our most important class is our MySQL Client class.It is responsible fro bothh connecting,inserting and retrieving data and handling errors appropriately.We are using the easy to use yet efficient Android Networking Library.
package com.tutorials.hp.mysqllistviewbool.mMySQL;
import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.JSONArrayRequestListener;
import com.tutorials.hp.mysqllistviewbool.mAdapter.ListViewAdapter;
import com.tutorials.hp.mysqllistviewbool.mModel.Spacecraft;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class MySQLClient {
//SAVE/RETRIEVE URLS
private static final String DATA_INSERT_URL="http://10.0.2.2/android/Aristotle/crud.php";
private static final String DATA_RETRIEVE_URL="http://10.0.2.2/android/Aristotle/index.php";
//INSTANCE FIELDS
private final Context c;
private ListViewAdapter adapter ;
public MySQLClient(Context c) {
this.c = c;
}
/*
SAVE/INSERT
*/
public void add(Spacecraft s, final View...inputViews)
{
if(s==null)
{
Toast.makeText(c, "No Data To Save", Toast.LENGTH_SHORT).show();
}
else
{
AndroidNetworking.post(DATA_INSERT_URL)
.addBodyParameter("action","save")
.addBodyParameter("name",s.getName())
.addBodyParameter("propellant",s.getPropellant())
.addBodyParameter("technologyexists",String.valueOf(s.getTechnologyExists()))
.setTag("TAG_ADD")
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
if(response != null)
try {
//SHOW RESPONSE FROM SERVER
String responseString = response.get(0).toString();
Toast.makeText(c, "PHP SERVER RESPONSE : " + responseString, Toast.LENGTH_SHORT).show();
if (responseString.equalsIgnoreCase("Success")) {
//RESET VIEWS
EditText nameTxt = (EditText) inputViews[0];
Spinner spPropellant = (Spinner) inputViews[1];
nameTxt.setText("");
spPropellant.setSelection(0);
}else
{
Toast.makeText(c, "PHP WASN'T SUCCESSFUL. ", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(c, "GOOD RESPONSE BUT JAVA CAN'T PARSE JSON IT RECEIVED : "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
//ERROR
@Override
public void onError(ANError anError) {
Toast.makeText(c, "UNSUCCESSFUL : ERROR IS : "+anError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
/*
RETRIEVE/SELECT/REFRESH
*/
public void retrieve(final ListView lv)
{
final ArrayList<Spacecraft> spacecrafts = new ArrayList<>();
AndroidNetworking.get(DATA_RETRIEVE_URL)
.setPriority(Priority.HIGH)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
JSONObject jo;
Spacecraft s;
try
{
for(int i=0;i<response.length();i++)
{
jo=response.getJSONObject(i);
int id=jo.getInt("id");
String name=jo.getString("name");
String propellant=jo.getString("propellant");
String techExists=jo.getString("technologyexists");
s=new Spacecraft();
s.setId(id);
s.setName(name);
s.setPropellant(propellant);
s.setTechnologyExists(techExists.equalsIgnoreCase("1") ? 1 : 0);
spacecrafts.add(s);
}
//SET TO SPINNER
adapter =new ListViewAdapter(c,spacecrafts);
lv.setAdapter(adapter);
}catch (JSONException e)
{
Toast.makeText(c, "GOOD RESPONSE BUT JAVA CAN'T PARSE JSON IT RECEIEVED. "+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
//ERROR
@Override
public void onError(ANError anError) {
anError.printStackTrace();
Toast.makeText(c, "UNSUCCESSFUL : ERROR IS : "+anError.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
(c). ListViewAdapter.java
We also have our ListView adapter to map our dataset to the adapterview.
Oclemy
Android MySQL – Select Multiple Columns and Fill Custom ListView
Android MySQL – Select Multiple Columns and Fill Custom ListView Tutorial
How to select multiple columns from mysql database and populate a custom listview with multiple textviews.
Overview
Welcome. In this class we are going to look at MySQL database. How to connect to MySQL, retrieve multiple columns and rows from a given database table and bind them to a custom ListView.
That ListView will have several fields, each representing a given record column from our mysql database table.
These fields will include:
Our application will have the following classes:
Spacecraft.java
CustomAdapter.java
Connector.java
HttpURLConnection
object.DataParser.java
Downloader.java
MainActivity.java
Tools Used
These are the tools we used to create the project:
Let’s go.
1. PHP Code
Here’s our PHP Code to select multiple columns data from our mysql database and return it in json format.
Am using Wamp:
C:wampwwwandroidspacecraft_select.php
.2. Setup
(a). Create Basic Activity Project
(b). Project Structure
Here’s our project structure:
(c). Build.Gradle
Our app level(app folder) build.gradle.
AndroidStudio allows us to add our application dependencies right here using
compile
statements.So we add our dependencies here. You may use later versions of the dependencies.
(d). AndroidManifest.xml
We add internet permission here.
3. Create User Interface
User interfaces are typically created in android using XML layouts as opposed to direct java coding.
Here are our layouts for this project:
(a). activity_main.xml
(b). content_main.xml
This layout gets included in your activity_main.xml.
We define our UI widgets here.
(c). model.xml
This is our custom row layout. Our model layout.
4. Java Code
(a). Spacecraft.java
Android is normally written in Java programming language. Java classes are normally organized in packages. This class will have the
com.tutorials.hp.mdmysqlselect.mDataObject
package.This class is a public class and represents a single spacecraft for us.
The class will have the following instance fields:
We create the getters and setters of these instance fields.
(b). CustomAdapter.java
This class will be deriving from
android.widget.BaseAdapter
. This class is public class.This class will maintain a couple of instance fields:
model.xml
layout.The constructor of this class will take in a Context object and an ArrayList of spacecrafts objects.
Then inside the Constructor we assign those objects to their respective class instance fields that we had defined.
We then initialiaze our LayoutInflater class:
inflater= (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE)
assigning to LayoutInflater class.LayoutInflater instance will later allow us inflate our XML layout into view object.
After deriving from baseadapter, we will be forced to implement a couple of abstract methods.
These include :
getCount()
– return the number of spacecrafts to bind to our ListView.getItem()
– get a single spacecraft object.getView()
– inflate themodel.xml
layout and return it as a view object.(c). Connector.java
Next we come to our
Connector.java
class.This class is a public class with one static method.
This method is our
connect(..)
method. This method will take a string object we are callingurlAddress
to represent the URL string to our server side PHP script that will allow us fetch data from mysql database.This method will return us a
java.net.HttpURLConnection
.We’ll have a try-catch block, catching two exceptions :
java.net.MalformedURLException
– Raised when a malformed URL is encountered.java.io.IOException
– Raised when an IO(Input Output) error has occured.First we attempt to instantiate a
java.net.URL
passing in our URL address. URL stands for Uniform Resouce Locator and points to a Resource in a the World Wide Web. In this case that resource will be our php script.url.openConnection()
will return us a URLConnection object which represents the connection to the remote object referred to by the URL.We cast that
URLConnection
to HttpURLConnection. HttpURLConnection is a url connection which supports HTTP specific features. It works with the HTTP protocol.con.setRequestMethod()
will set the HTTP Request method that we support. These can be :We use
GET
since we are fetching data.con.setReadTimeout()
will specify the timeout for reading our resouce whilecon.setConnectTimeout()
indicates the timeout for our connection.con.setDoInput()
indicates that our connection supports input of data.(d). DataParser.java
This is our Data Parser class.
(e). Downloader.java
(f). MainActivity.java
Oclemy
 Android MySQL – Select and Show in ListView(HTTPURLConnection).
Previously we had seen how to connect to mysql and isnert data into database from android. Well that was a HTTP POST request we were making.
We can also retrieve data and show them into a ListView.
While fetching data we will show a progress dialog.
HttpURLConnection
Still we use the standard Android Networking API that is
java.net.HTTURLConnection
. Read more about HttpUrlConnection here.Our MySQL Database
Here’s our MySQL table structure:
We have the following fields:
Read more about mysql here.
Project Structure
Here’s the project structure:
Let’s go.
1. Gradle Scripts
In our app level build.gradle we add some dependencies.
(a). Build.gradle
We add
android.support:appcompat-v7
andandroid.support:design
.2. Our PHP Script
Here’s the PHP script that will connect to the MySQL database.
3. AndroidManifest.xml
Add the permission for internet in the androidmanifest.xml.
4. Layouts
Let’s create some layouts.
(a). activity_main.xml
Our MainActivity’s primary layout. Will get inflated into MainActivity user interface.
At the root we have
android.support.design.widget.CoordinatorLayout
.android.support.design.widget.AppBarLayout
tag.android.support.v7.widget.Toolbar
tag.android.support.design.widget.FloatingActionButton
tag.content_main.xml
which will render our other views and widgets.(b). content_main.xml
Our content_main.xml layout. The root tag is
RelativeLayout
.It has the following responsibilities:
activity_main.xml
to form the MainActivity layout.5. Java Classes
We have three custom java classes.
(a). Downloader.java
Our
Downloader.java
class, a public class that will derive fromandroid.os.AsyncTask
. This provides us with easy to use threading capabilities.The purposes of this class includes:
android.content.Context
object, a URL address and a ListView widget from the MainActivity.java.net.HTTPURLConnection
.IOException
andMalformedURLException
.Parser
object, pass Context, downloaded string and listview.And execute it.(b). Parser.java
This is our custom
Parser
class. The class still extendsandroid.os.AsyncTask
.This class will parse our JSON string and fill our listview.
It has the following roles:
Downloaded
class.doInbackground()
method.(c). MainActivity.java
Our public class that will be the launcher activity. It will derive from
android.support.v7.app.AppCompatActivity
.This class the following responsibilities:
deriving from
android.support.v7.app.AppCompatActivity
.||2.|Listen to activity creation callbacks by overrding the
onCreate()
method.||3.|Invoke the
onCreate()
method of the parent Activityclass and tell it of a Bundle we’ve received. |
|4.|Inflate the
activity_main.xml
into a View object and setit as the content view of this activity.|
|5.| Define our URL address. This URL address leads to ou PHP script|
|6.| Reference the
android.support.v7.widget.Toolbar
and set it to the SupportActionBar.||7.| Reference ListView from layout.|
|8.| Instantiate
Downloader
class. Pass in the URL addtess, ListView and Context.||9.| Execute the download operation.|
Download
You can download the code here.
Oclemy
Android MySQL – ListView CheckBoxes – INSERT,SELECT,SHOW
This is an Android MySQ ListView with CheckBoxes tutorial. We want to see how to work with boolean text values. We save them into mysql and also retrieve them.
Video Tutorial(ProgrammingWizards TV Channel)
Well we have a video tutorial as an alternative to this. If you prefer tutorials like this one then it would be good you subscribe to our YouTube channel.
Basically we have a TV for programming where do daily tutorials especially android.
Android MySQL ListView CheckBoxes Insert, Select Show Example
Let’s look at our example:
MySQL Table
Here’s our mysql table structure:
Project Structure
Here’s our project structure.
1. PHP Code
Here are our php code. Place them in the same folder.
(a) Constants.php
(b) CRUD.php
(c) DBAdapter.php
(d) Index.php
2. Gradle Scripts
Here are our gradle scripts in our build.gradle file(s).
(a). build.gradle(app)
Here’s our app level
build.gradle
file. We have the dependencies DSL where we add our dependencies.This file is called app level
build.gradle
since it’s located in the app folder of the project.If you are using Android Studio version 3 and above use
implementation
keyword while if you are using a version less than 3 then still use thecompile
keyword.Once you’ve modified this
build.gradle
file you have to sync your project. Android Studio will indeed prompt you to do so.[notice]
We are using Fast Android Networking Library as our HTTP Client. You may use newer versions.
[/notice]
3. Resoources.
Android platform provides a powerful and flexible way of adding static content as a resource.
These static content will also be packaged into the APK file. The static content will be stored either as a resource or as an asset.
Resources belong to a given type. These types can be:
Let’s start by looking at the layout resources
(a). model.xml
Our row model layout.
(b). content_main.xml
Our
content_main
layout. This layout is being inserted into ouractivity_main.xml
.(c). activity_main.xml
Our
activity_main
layout.(a). Spacecraft.java
First we have a data object POJO class as below.
(b). MySQLClient.java
Our most important class is our MySQL Client class.It is responsible fro bothh connecting,inserting and retrieving data and handling errors appropriately.We are using the easy to use yet efficient Android Networking Library.
(c). ListViewAdapter.java
We also have our ListView adapter to map our dataset to the adapterview.
(d). MainActivity.java
The main activity.
Download
Hey,everything is in source code reference that is well commented and easy to understand and can be downloaded below.
Also check our video tutorial it’s more detailed and explained in step by step.