Shanaz K
Shanaz K

Reputation: 698

Display received data from .php script in ListView

How to put data from database table in listView using Android code.

This is PHP code, I need Android code for this:

$your_querry="select * from member ";
$query=mysql_query($your_querry);
$list=array();
while($row=mysql_fetch_assoc($query))
{
    $list[]=$row;
}

echo json_encode($list);

Upvotes: 2

Views: 1031

Answers (2)

ROR
ROR

Reputation: 271

for this question use JSONParser.java and ListAdapter.java ,

if your listview contain image I strongly recommend to you use

1-MemoryCache.java.
2-FileCache.java.
3-ImageLoader.java.
4-Utils.java.

that's all I think

Upvotes: 3

Simon
Simon

Reputation: 6363

Try something like this

DefaultHttpClient   httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpGet httppost = new HttpGet("path/to/your/php-script");

httpGet.setHeader("Content-type", "application/json");

InputStream inputStream = null;
String result = null;
try {
    HttpResponse response = httpclient.execute(httppost);           
    HttpEntity entity = response.getEntity();

    inputStream = entity.getContent();

    // Now parse the JSON with some JSON library like Jackson, Gson or JSON.org
    ...
    // Then fill the listView with the objects you parsed
    ...

Upvotes: 1

Related Questions