Download Code

Android Load MYSQL Data ListView

In android load mysql data listview tutorial you will learn android load data from database MySQL into a custom ListView using PHP,JSON Parser and HTTP Components in android application.

First you need XAMPP Server(Localhost) from where you will load data database mysql.

Create new database mysql “codeclogin” on XAMPP Server(Localhost) .

Create table “item_group” and insert items.

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

 

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

load_list.php

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

Alright you are done with Server End.

Create new android load mysql data listview application project.Follow the steps.

  • Go to activity_main.xml and add ListView.
  • Create new XML layout list_item.xml , add ImageView and a TextView.
  • Create a class Product.java used for set and get name of product.
  • Create another class CustomAdapter.java which returns itemView within ListView.
  • Next MainActivity.java which you will use to load data in listview.Using arrayList,AsyncTask and Parse JSON data.
  • At last add INTERNET and ACCESS_NETWORK_STATE permissions in Android Manifest.xml File.

activity_main.xml

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

list_item.xml

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

Product.java

package developer.loaddatalistview;

public class Product {

	private String pName;

	public void setpName(String pName){
		this.pName=pName;
	}
	public String getpName(){
		return pName;
	}
}

CustomAdapter.java

package developer.loaddatalistview;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter {
	int groupid;
	ArrayList records;
	Context context;
	public CustomAdapter(Context context, int vg, int id, ArrayList records) {
		super(context, vg, id, records);
		this.context = context;
		groupid = vg;
		this.records = records;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View itemView = inflater.inflate(groupid, parent, false);
		TextView textName = (TextView) itemView.findViewById(R.id.pro_name);
		textName.setText(records.get(position).getpName());
		return itemView;
	}
}

MainActivity.java


package developer.loaddatalistview;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;


public class MainActivity extends Activity{

	Activity context;
	HttpPost httppost;
	StringBuffer buffer;
	HttpResponse response;
	HttpClient httpclient;
	ProgressDialog pd;
	CustomAdapter adapter;
	ListView listProduct;
	ArrayList records;
	
	
	protected void onCreate(Bundle savedInstanceState) {
		//TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		context=this;
		records=new ArrayList();
		listProduct=(ListView)findViewById(R.id.product_list);
		adapter=new CustomAdapter(context, R.layout.list_item,R.id.pro_name, records);
		listProduct.setAdapter(adapter);
		listProduct.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
			}
		});
	}

	public void onStart(){
		super.onStart();
		//execute background task
		BackTask bt=new BackTask();
		bt.execute();
	}

	private class BackTask extends AsyncTask<Void,Void,Void>{
		protected void onPreExecute(){
			super.onPreExecute();
			pd = new ProgressDialog(context);
			pd.setTitle("Retrieving data");
			pd.setIcon(R.drawable.ic_launcher);
			pd.setMessage("Please wait...");
			pd.setCancelable(true);
			pd.setIndeterminate(true);
			pd.show();
		}
		protected Void doInBackground(Void...params){
			InputStream is=null;
			String result="";
			try{
				httpclient=new DefaultHttpClient();
				httppost= new HttpPost("http://192.168.1.100/LoadData/load_list.php");
				response=httpclient.execute(httppost);
				HttpEntity entity = response.getEntity();
				// Get our response as a String.
				is = entity.getContent();
			}catch(Exception e){
				if(pd!=null)
					pd.dismiss(); //close the dialog if error occurs
				Log.e("ERROR", e.getMessage());
			}
			//convert response to string
			try{
				BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);
				StringBuilder sb = new StringBuilder();
				String line = null;
				while ((line = reader.readLine()) != null) {
					sb.append(line+"\n");
				}
				is.close();
				result=sb.toString();
			}catch(Exception e){
				Log.e("ERROR", "Error converting result "+e.toString());
			}
			//parse json data
			try{
				result=result.substring(result.indexOf("["));
				JSONArray jArray =new JSONArray(result);
				for(int i=0;i<jArray.length();i++){
					JSONObject json_data =jArray.getJSONObject(i);
					Product p=new Product();
					p.setpName(json_data.getString("name"));
					records.add(p);
				}
			}
			catch(Exception e){
				Log.e("ERROR", "Error pasting data "+e.toString());
			}
			return null;
		}
		protected void onPostExecute(Void result){
			if(pd!=null) pd.dismiss(); //close dialog
			Log.e("size", records.size() + "");
			adapter.notifyDataSetChanged(); //notify the ListView to get new records
		}
	}
}

Android Manifest.xml

android load data,database mysql,JSON,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

Now run your android load mysql data listview application project.

android load data,JSON,database mysql,JSONParser,JSONObject,JSONArray,Listview in android,listview, customer listview,custom listview in android,listview with image, custom listview with image in android,how to load data in listview, how to load data in custom listview, how to load data in custom listview in android, how to load data from database, how to load data from mysql database, how to load data in listview using mysql database, how to load data in listview using mysql database in android, how to connect android app with XAMPP server, how to load data from local server to android application, how to load data from localhost,how to load data from localhost to android application,how to load data from localhost to listview in android, asynctask,asynctask in android,background computation in android, onPreexecute,onPostExecute,onStart,doInbackground,http,httpclient,httpget, httppost,defaulthttpclient,http client library,http client libaray in android,how to get data using JSON,BufferedReader,InputStreamReader, Progress dialog,progress dialog in android,adapter,listadapter, full screen view,full screen view in android application,ArrayAdapter, ArrayAdapter in android,setonitemclicklistener,setonitemclicklistener in android,setonitemclicklistener in listview android, how to load data from database tutorial,how to load data from database source code,how to execute asynctask,how to execute asynctask in android,android load mysql,android load mysql data,android load mysql data listview,mysql data listview,

That’s it for this Android load mysql data listview tutorial.

Thanks.