Populating Android Listview With JSON Based Data Fetched From MySQL Server Using PHP



In this tutorial, we’ll create a simple android application that show a list of popular android apps complete with their icons, total downloads and ratings data. Note, all the apps data we use in this tutorial is sample data. We use android List View to show list of apps. The data for the list view is fetched from MySQL Server in JSON(Javascript Object Notation) format. We use PHP as server side language to connect to MySQL database server.

Before we go into step by step explanation to create the application, we’ll review application basic concept and all of tools that is required by the application.

JSON Overview

JSON (Javascript Object Notation) is an independent data exchange format. A JSON object is a set of key / value pairs which starts with “{” and ends with “}”. Here is sample of JSON that will be used in this tutorial.

var json = {
    'title' : 'Facebook',
    'rating' : 5,
    'total_dl' : 10990998,
    'icon' : 'facebook'
};

An array of json can be written as follow:

var json = [
    {'title' : 'Facebook',
    'rating' : 5,
    'total_dl' : 10990998,
    'icon' : 'facebook'},
    {'title' : 'Twitter',
    'rating' : 5,
    'total_dl' : 12343487,
    'icon' : 'twitter'},
    {'title' : 'Whatsapp',
    'rating' : 4,
    'total_dl' : 5635989,
    'icon' : 'whatsapp'}
    ];


Basic Concept

As I’ve stated before, we’ll create simple android application that show a list of top application. We use android list view to display the data. The list data come from MySQL server. So this application will have a http connection feature. Communication between server and android application is use JSON based data. In this tutorial we’ll use apached server in localhost that running AVD (Android Virtual Device).
The data that are fetched from server including applicatoin title, rating, total download and icon name. For simplicity of the tutorial, we’ll use an icons that are saved in /res/drawable folder for applications. This will reduce the complexity of downloading the icons from server.
Below is final screenshot of our tutorial

Populate Listview Using JSON

Populate Listview Using JSON



Server Side Task

1. Creating A Database in MySQL

Before creating a database in MySQL, make sure you’ve create a user to login into the MySQL server. In this tutorial, we use a default user root with blank password.
We’ll create a simple database scheme for the application. The database will be used to store application data. Execute the following sql to create such database.

CREATE DATABASE apps;

Now, we have a database apps. We need to create a table in database apps that will store the application title, total download, rating and icon file name. Execute the following sql to create the table.

CREATE TABLE `app_data`(
    `id` int unsigned NOT NULL AUTO_INCREMENT,
    `app_title` varchar(150) NOT NULL,
    `total_dl` int unsigned NOT NULL default 0,
    `rating` int unsigned NOT NULL default 0,
    `icon` varchar(120) NOT NULL,
    primary key(`id`)
);

Now, we must put sample application data into the table. Execute the following sql to create sample application data.

INSERT INTO app_data VALUES(null, "Facebook", 20099099, 5, "facebook");
INSERT INTO app_data VALUES(null, "Twitter", 11342099, 5, "twitter");
INSERT INTO app_data VALUES(null, "Google +", 10123023, 4, "google");
INSERT INTO app_data VALUES(null, "Whatsapp", 10033876, 3, "whatsapp");
INSERT INTO app_data VALUES(null, "Youtube", 10023444, 4, "youtube");
INSERT INTO app_data VALUES(null, "Line", 9023434, 5, "line");
INSERT INTO app_data VALUES(null, "Kakao Talk", 8247836, 3, "kakao");
INSERT INTO app_data VALUES(null, "Linked In", 784736, 4, "linkedin");
INSERT INTO app_data VALUES(null, "Angry Bird", 693847, 2, "angrybird");
INSERT INTO app_data VALUES(null, "Skype", 528374, 3, "skype");


2. Create PHP Script to Fetch the Data

The database now ready, we need create a PHP script that connect to MySQL server and get the application data. Then the application data is converted into JSON string that will send into client (android application). This script use user root with blank password to login into MySQL server, you can change them to meet your server account.

<?php
$host = "localhost"; // host of MySQL server
$user = "root"; // MySQL user
$pwd = ""; // MySQL user's password
$db = "apps"; // database name

// Create connection
$con = mysqli_connect($host, $user, $pwd, $db);

// Check connection
if(mysqli_connect_errno($con)) {
    die("Failed to connect to MySQL: " . mysqli_connect_error());
} 

// query the application data
$sql = "SELECT * FROM app_data ORDER By id";
$result = mysqli_query($con, $sql);

// an array to save the application data
$rows = array();

// iterate to query result and add every rows into array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $rows[] = $row; 
}

// close the database connection
mysqli_close($con);

// echo the application data in json format
echo json_encode($rows);

Save above source as PHP file and give a name apps.php and you must place it in apache document root, for example http://localhost/test/apps.php.

3. Testing PHP Script in A Browser

We must test the PHP script we’ve created to make sure the script works well. Open your browser and goto http://localhost/test/apps.php (the url may depend on your environtment). If the script works well, you’ll see the following result in your browser.

JSON In Browser

JSON In Browser



Client Side Task (Android Application)

After the server side is ready and tested, now we’ll create an android application that will create a http request to PHP script that we’ve created previously to get all application data and display the data in a list view. In order to display all of data like application title, total downloads, rating and icon, we must create a custom adapter for the list view.
Open your Eclipse IDE and create new android application. Use JsonDemo as the project’s name.
Do the following step by step to create the application.

1. Create Main Layout File

This file is an xml layout file that defines the main user interface. It contains a list view that will display all of the application data.
Save below source code as /res/layout/activity_main.xml.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>


2. Create Custom List View Layout File

This file is an xml layout file. It responsibles to define a custom view the list view that is contained in the main layout. This file will be used in the custom adapter that will be defined later. The layout contains 3 TextView and 1 ImageView. The image view is used to display the application icon. It is placed on the left. First text view is used to display application’s title. It is placed on the right of the icon. Second text is used to display application’s rating. It is placed on the bottom application’s title. The last text view is used to display the application’ total download.
Save below source code as /res/layout/app_custom_list.xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/appIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"        
        android:layout_marginLeft="3dp"
        android:layout_marginTop="3dp"
        android:src="@drawable/facebook" />
    <TextView
        android:id="@+id/titleTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/appIcon"
        android:layout_toRightOf="@id/appIcon"
        android:layout_marginLeft="3dp"
        android:text="Application Title"
        android:textSize="22dp"/>

    <LinearLayout
        android:id="@+id/ratingCntr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/appIcon"
        android:layout_below="@id/titleTxt"
        android:layout_marginLeft="5dp" >
    </LinearLayout>

    <TextView
        android:id="@+id/dlTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/titleTxt"
        android:layout_alignParentRight="true"
        android:layout_marginRight="3dp"
        android:text="0 dl" />    

</RelativeLayout>


3. Create Application Value Object File

This file is a java object class that represents an application value object. It has several properties that are mapped from the app_data table from our database. It has properties such as application name, total downloads, rating and icon. Below is definition of the file. Below is the source code that define application value object. Save it as /src/com/sj/jsondemo/Application.java.

package com.sj.jsondemo;

public class Application {
    private String title;
    private long totalDl;
    private int rating;
    private String icon;
    
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public long getTotalDl() {
        return totalDl;
    }
    public void setTotalDl(long totalDl) {
        this.totalDl = totalDl;
    }
    public int getRating() {
        return rating;
    }
    public void setRating(int rating) {
        this.rating = rating;
    }
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
}


4. Create Custom Adapter File

This file is list view’s custom adapter that will inflate /res/layout/app_custom_list.xml layout file. It’s constructor is defined with 1 parameter. The parameter is an array list of application value object. The adapter will inflates the layout for each application object in the array list and change the application title, rating, total downloads and icons dynamically.
Below is source code that defines the custom adapter. Save it as /src/com/sj/jsondemo/ApplicationAdapter.java.

package com.sj.jsondemo;

import java.text.NumberFormat;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ApplicationAdapter extends ArrayAdapter<Application>{
    private List<Application> items;
    
    public ApplicationAdapter(Context context, List<Application> items) {
        super(context, R.layout.app_custom_list, items);
        this.items = items;
    }
    
    @Override
    public int getCount() {
        return items.size();
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        
        if(v == null) {
            LayoutInflater li = LayoutInflater.from(getContext());
            v = li.inflate(R.layout.app_custom_list, null);            
        }
        
        Application app = items.get(position);
        
        if(app != null) {
            ImageView icon = (ImageView)v.findViewById(R.id.appIcon);
            TextView titleText = (TextView)v.findViewById(R.id.titleTxt);
            LinearLayout ratingCntr = (LinearLayout)v.findViewById(R.id.ratingCntr);
            TextView dlText = (TextView)v.findViewById(R.id.dlTxt);
            
            if(icon != null) {
                Resources res = getContext().getResources();
                String sIcon = "com.sj.jsondemo:drawable/" + app.getIcon();
                icon.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
            }
            
            if(titleText != null) titleText.setText(app.getTitle());
            
            if(dlText != null) {
                NumberFormat nf = NumberFormat.getNumberInstance();
                dlText.setText(nf.format(app.getTotalDl())+" dl");            
            }
            
            if(ratingCntr != null && ratingCntr.getChildCount() == 0) {        
                /*
                 * max rating: 5
                 */
                for(int i=1; i<=5; i++) {
                    ImageView iv = new ImageView(getContext());
                    
                    if(i <= app.getRating()) {
                        iv.setImageDrawable(getContext().
                        getResources().getDrawable(R.drawable.start_checked));
                    }
                    else {                
                        iv.setImageDrawable(getContext().
                        getResources().getDrawable(R.drawable.start_unchecked));
                    }
                    
                    ratingCntr.addView(iv);
                }
            }
        }
        
        return v;
    }
}


5. Create An Async Task File To Get The Data From Server

This file responsibles to get all the application data by creating a http request to PHP script. It is defined by subclassed AsyncTask object class. This means the task will be execute in the background, so it never block the user interface. When the task is executed, a progress bar will be shown to make the interface user friendly. This file communicate to activity via a listener that we’ll create later. This communication is important because we need to notify the activity when all the data has been fetched.
Below is the source code that define the async task. Save it as /src/com/sj/jsondemo/FetchDataTask.java.

package com.sj.jsondemo;

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

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

import android.os.AsyncTask;

public class FetchDataTask extends AsyncTask<String, Void, String>{
    private final FetchDataListener listener;
    private String msg;
    
    public FetchDataTask(FetchDataListener listener) {
        this.listener = listener;
    }
    
    @Override
    protected String doInBackground(String... params) {
        if(params == null) return null;
        
        // get url from params
        String url = params[0];
        
        try {
            // create http connection
            HttpClient client = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);
            
            // connect
            HttpResponse response = client.execute(httpget);
            
            // get response
            HttpEntity entity = response.getEntity();
            
            if(entity == null) {
                msg = "No response from server";
                return null;        
            }
         
            // get response content and convert it to json string
            InputStream is = entity.getContent();
            return streamToString(is);
        }
        catch(IOException e){
            msg = "No Network Connection";
        }
        
        return null;
    }
    
    @Override
    protected void onPostExecute(String sJson) {
        if(sJson == null) {
            if(listener != null) listener.onFetchFailure(msg);
            return;
        }        
        
        try {
            // convert json string to json array
            JSONArray aJson = new JSONArray(sJson);
            // create apps list
            List<Application> apps = new ArrayList<Application>();
            
            for(int i=0; i<aJson.length(); i++) {
                JSONObject json = aJson.getJSONObject(i);
                Application app = new Application();
                app.setTitle(json.getString("app_title"));
                app.setTotalDl(Long.parseLong(json.getString("total_dl")));
                app.setRating(Integer.parseInt(json.getString("rating")));  
                app.setIcon(json.getString("icon"));
                
                // add the app to apps list
                apps.add(app);
            }
            
            //notify the activity that fetch data has been complete
            if(listener != null) listener.onFetchComplete(apps);
        } catch (JSONException e) {
            msg = "Invalid response";
            if(listener != null) listener.onFetchFailure(msg);
            return;
        }        
    }
    
    /**
     * This function will convert response stream into json string
     * @param is respons string
     * @return json string
     * @throws IOException
     */
    public String streamToString(final InputStream is) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder(); 
        String line = null;
        
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } 
        catch (IOException e) {
            throw e;
        } 
        finally {           
            try {
                is.close();
            } 
            catch (IOException e) {
                throw e;
            }
        }
        
        return sb.toString();
    }
}


6. Create Fetch Data Listener

This file is simple Java interface. It has two method’s declarations, onFetchCompleted and onFetchFailure. onFetchCompleted method will be called from FetchDataTask when data fetching is complete. onFetchFailure will be called from FetchDataTask when data fetching is failure.
Save below source code as /src/com/sj/jsondemo/FetchDataListener.java.

package com.sj.jsondemo;

import java.util.List;

public interface FetchDataListener {
    public void onFetchComplete(List<Application> data);
    public void onFetchFailure(String msg);
}


7. Create Activity

This is main activity that will inflate /res/layout/activity_main.xml to create main user interface. When the activity is created, it’s create new FetchDataTask instance and call execute method of the instance. The task runs and start to get all application data in the background. Before execute the task, the activity show progress bar to the user to indicate that the system is loading the data.
This activity also implements FecthDataListener and overriden onFetchCompleted and onFetchFailure. onFetchFailure is used by activity to hide the progress bar and display failure message to user. onFetchCompleted is used by activity to hide the progress bar and display the application data into the list.
The apache server that we used is localhost which same as host that run AVD(Android Virtual Device), so to refers this host from AVD, we must use IP address 10.0.2.2. For more information please visit Android Developer Site.
Save below source code as /src/com/sj/jsondemo/MainActivity.java.

package com.sj.jsondemo;

import java.util.List;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends ListActivity implements FetchDataListener{
    private ProgressDialog dialog;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        setContentView(R.layout.activity_main);        
        initView();   
    }

    private void initView() {
        // show progress dialog
        dialog = ProgressDialog.show(this, "", "Loading...");
        
        String url = "http://10.0.2.2/test/apps.php";
        FetchDataTask task = new FetchDataTask(this);
        task.execute(url);
    }
    
    @Override
    public void onFetchComplete(List<Application> data) {
        // dismiss the progress dialog
        if(dialog != null)  dialog.dismiss();
        // create new adapter
        ApplicationAdapter adapter = new ApplicationAdapter(this, data);
        // set the adapter to list
        setListAdapter(adapter);        
    }

    @Override
    public void onFetchFailure(String msg) {
        // dismiss the progress dialog
        if(dialog != null)  dialog.dismiss();
        // show failure message
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();        
    }
}

8. Create Manifest File

The application make a http request, so the the manifest file must contains network usage permission. Below is complete manifest file. Save it as Android.Manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sj.jsondemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sj.jsondemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Related Posts:

Android, PHP
  • Biginner

    good tutorial ..

  • heru

    I tried yesterday and it fit in the coding can not run the server how to retrieve data.,.,., just show “No network conection”

    • Jappi Patel

      I tried this code and it fit in the coding can not run the server how to retrieve data.,.,., just show “No network conection”…can you plzzz help me…

      • Guest

        Plzz help meto solve out this problem .

        • KHE-KHE

          Add permittion in menifest 😀

  • PirataCS

    I had been struggling with this and your tutorial was very useful. Working great now! Thanks.

    • sustecha

      would you mind help me I already made all the steps but still got
      “your application has stopped unexpectedly try again later”

  • Jawad

    It dont’t Connect with database

  • Victor Zheng

    Thanks for your tutorial.

    How can I add the response of clicking on the item of the list? like when I click on one of the items of the list, how can I do to make it displays a dialog? .

    Thanks!

    • Aleksandar

      Did you manage to find answer on your question? I m having same problem…

  • Aleksandar

    It’s working fine, but how can I add setOnClick function? I would like that those items are clickable and to start something from them…
    Thanks for this tutorial

    • Laurence

      i also have the same question about setonclick

    • Alexis

      Hi Aleksandar!
      Do you find a way to add setOnClick function? Please tell me your solution. I’m new.

    • Archana

      Hi Aleksandar, I cant see the data from database, Showin as No network connection please help me.

  • Hame

    when you instantiate the task –> FetchDataTask task = new FetchDataTask(this); I can`t really figure what (this) does. is this saying that the FetchDataListener object “belongs” to task?

    • http://www.semurjengkol.com/ Fazri

      ‘this’ here means the instance of MainActivity it self, because MainActivity implements FetchDataListener

  • Alvic

    Hi,
    It is possible pull the image from server something like
    http://192.168.0.100/images/$mysqldata/

    sample data
    —————————————————————-
    | id | app_title | total_dlrating | icon_url
    —————————————————————-
    | 0 | Facebook | 200990995 | facebook.png
    —————————————————————-
    | 1 | twitter | 200990995 | twitter.jpg
    —————————————————————-

    instead using>>> String sIcon = “com.sj.jsondemo:drawable/” + app.getIcon();
    ?

  • naffie

    Hey,thank you for this tutorial..very helpful.I have a question though,i used this for my own quiz app and i’m having a problem with parsing a nested JSON.I cannot display the inner elements i.e the anwers.I only get the description in the listview..How do i edit my code in the FetchDataTask..here’s my link to my JSON.Than you! http://localhost/webservice/new_questions.php

    • http://www.semurjengkol.com/ Fazri

      You can get the answer array using this way:

      JSONArray aJson = new JSONArray(sJson);

      for(int i=0; i<aJson.length(); i++) {
      JSONObject json = aJson.getJSONObject(i);
      JSONArray answer = json.getJSONArray('answers');
      }

      • naffie

        Hi Fazri…thank you so much!..that really pushed me in the right direction

  • Alexis

    Hi !
    Thank you for this tutorial. Very helpful.
    How can i add setOnClick function to items? I’m new.

    • http://www.semurjengkol.com/ Fazri

      You can override onListItemClick method in MainActivity.java

      @Override

      public void onListItemClick(ListView l, View v, int position, long id) {

      // do something here

      }

      then add a line in initView method (MainActivity.java):

      getListView().setOnClickListener(this);

      • Alexis

        Thank you very much!!!

      • Amit

        its not working ! any other way to achieve this ?

  • Muaath assaf

    the worst video i see it dose not work

  • beni

    can u help my how can i parse the data in expandable listview

    • http://www.semurjengkol.com/ Fazri

      You can override onListItemClick method in MainActivity.java

      @Override

      public void onListItemClick(ListView l, View v, int position, long id) {

      //start activity here

      }

      then add a line in initView method (MainActivity.java):

      getListView().setOnClickListener(this);

  • ckm

    this tutorial help for me lot.but i want to do little changes,when i click one listview then it open new activity and display the information in the listview with more details.i tried to do this,but i can’t.please help me to do this thing.

  • trmlk

    For Some reason I can’t test in my tablet, but with emulator works ok.

    To resolve this problem I have created a webhost on 000webhost.com

  • richard robasto

    i’m beginner here on android programming
    i have a question sir :)

    what if you don’t have an image on the drawable folder
    and you only have an image on database how do you retrieve it?
    can you explain it to me?
    did i need to use a bitmap?
    or the same code like what you make?

    • Xavier KaSiris

      That is done via image link

  • Partha Chakraborty

    Great tutorial! It really helped me. However, I would like to get the icons from the server itself, not from the drawable folder. Please help me with this. Thanks in advance

  • Illuminate

    This was a great tutorial, however i want to be able to show the images from a file in the list view, how do i do this

  • hal

    great tutorial! I was wondering if you could answer a question for me. I am working on a project where the PHP file needs to get a variable from the device for the WHERE part of the database query.

    For example:
    $sql = “SELECT * FROM apps ORDER By id” WHERE rating = $rating;

    Could you show how to do this?

    • Taeeb Ahmad

      i have the same problem .. did u solve the problem??

  • http://jamiepaleschi.co.uk Jay A Paleschi

    Any way to make the results apply to a GRID view instead of a LIST view?

  • http://jamiepaleschi.co.uk Jay A Paleschi

    I have no errors in the code itself but the list will not appear, only giving “Invalid Response” on the emulator. I know my URL is correct, though….

    Any advice?

    • Luiz Cavalieri

      Hi Jay did you get the answer? I’m having the same problem…

  • Aayat

    Very helpful, just would like to state that in the downloaded source code the (in the apps.php) rather than $db = “test” it should be $db = “apps” 😀 Cheers!

  • phulee

    tks so much!

  • Umer Dar

    I didn’t use this code but it seems good. very nice

  • Jyoti

    how to write code to open a new activity which is again having listview and fetching data from database on click of a particular item.

  • James

    can i know how to retrieve images from mysql and display them in listview?i really need the source code for this part..thanks

  • Amit

    Great Work !!!

  • Amit

    Hi ! very nice example… I am a newbie in android… I just wanna know how to implement filter functionality in this example…I have searched lots of article but didn’t find. It would be very thankful to you..

  • Mubbi

    im getting invalid response whenever i try this, i know my url is working fine, can anyone help me out?

    • susheel

      change databse name in apps.php file as apps

      • Luiz Cavalieri

        I’m also having the same problem, and it is not the name of the database or any typo on the php… Can you help what could be as well?

  • nikos

    Nice example you have there, but I have a question, why when data are fetched from server (in Greek) are displayed as ????? how can I fix it

  • Muhammed Hussain

    how to open a new activity with detail of record when i click on listview

  • Muhammed Hussain

    How to open a detail activity when i clicked on listview.

  • Muhammed Hussain

    how to open a new activity with detail of record when i click on listview

  • sustecha

    I didn’t find any problem except run time error I got when I am trying to run the app
    “program has stopped unexpectedly try again later”
    could any body help me????

  • Aterrai Zakaria

    can you show me how whene i click one item it tell me what i click please ….. ????

  • Siddharth Bhardwaj

    for those who are not able to connect with database :

    I assume u have xampp server installed and in it apache and mysql are running

    STEP 1:Install connectify hotspot and run it on your pc now connect your phone to your laptops hotspot.

    STEP 2:Change the location of php file in your program to your hotspots ip adress usually it is http://192.168.186.1/apps.php
    if u think this is not correct ip run cmd and type ipconfig and press enter here u can see all the ip addresses.

    STEP 3:The php file should be present in C:/xampp/htdocs folder.

    Thats it!

  • https://hussainafridi.wordpress.com/ M Hussain Afridi

    Dear Sir, First of all Thanks.
    How to open a new Activity when i click on any listview record to open a detail record in new activity

  • Luiz Cavalieri

    I’m getting Invalid Response after the dialog is dismissed and no list is loaded… Also my setListAdapter is asking me if I want to create a setter, method or a property… it seems that is nothing as such on this tutorial…

  • https://hussainafridi.wordpress.com/ M Hussain Afridi

    Dear All Please help me anyone.

    i want to open a new activity when i click on any record of listview and show data in second activity

  • Manikanta

    Hi I am new to android, I have a doubt I am working same similar project as above example, I have the php script code which i need display the content in list view (with image & Content). I used the above code but it is not working, i am getting errors like below

    01-04 17:39:19.946 150-165/system_process E/ActivityManager: ANR in com.android.launcher
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: Reason: Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 }
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: Load: 4.08 / 2.02 / 1.9
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: CPU usage from 0ms to 24982ms later:
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 20% 150/system_server: 15% user + 4.3% kernel / faults: 455 minor 1 major
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 2% 36/surfaceflinger: 2% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 1.2% 254/com.android.launcher: 0.9% user + 0.3% kernel / faults: 30 minor 1 major
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 1.2% 46/adbd: 0.1% user + 1% kernel / faults: 288 minor
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 0.1% 1280/com.example.igetu.tmb1: 0.1% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 0% 29527/zygote: 0% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: +0% 10822/sh: 0% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 100% TOTAL: 77% user + 21% kernel + 0.3% softirq
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: CPU usage from 23280ms to 24348ms later with 99% awake:
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 19% 150/system_server: 13% user + 6.5% kernel / faults: 3 minor
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 14% 183/WindowManagerPo: 14% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 9.7% 165/ActivityManager: 0% user + 9.7% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 7.6% 182/WindowManager: 5.4% user + 2.1% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 11% 36/surfaceflinger: 11% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 9.8% 101/Binder_1: 9.8% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 7.1% 90/SurfaceFlinger: 7.1% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 5.3% 16807/Binder_3: 5.3% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 1.7% 189/Binder_2: 1.7% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 0.8% 36/surfaceflinger: 0% user + 0.8% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 11% 254/com.android.launcher: 8.9% user + 2.9% kernel / faults: 20 minor
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 33% 262/Signal Catcher: 33% user + 0% kernel
    01-04 17:39:19.946 150-165/system_process E/ActivityManager: 100% TOTAL: 83% user + 16% kernel

    please help me on this… My project is news project same as NewsHunt or Daily Hunt application