0

I'm trying to populate a listview with data picked from a remote database, using PHP to interrogate the database and return to the android code the results. After this I'd like to show the results in a listview (kinda like Twitter does). How can I achieve all of this?

This is the PHP code:

<?php
require 'jsonwrapper.php';

mysql_connect("****","*****","****");
mysql_select_db("****");

$q=mysql_query("SELECT * FROM articoli");

while($raw=mysql_fetch_assoc($q)) {
    $output[]=$raw;
}

print(json_encode($output));

mysql_close();
?>

From this I receive an array of strings like this:
[{"titolo":"TestData","articolo":"Vediamo ora se inserisce la data come gli ho detto di fare anche la scorsa volta. Solo che la scorsa volta non accettava il metodo di formattazione della data quindi inseriva una stringa vuota","data":"","media":"","idutente":""},{"titolo":"Prova","articolo":"contenuto dell'articolo di prova","data":"28032014_185338","media":"","idutente":""}]



I was thinking about receiving this array in a single string and then manipulate it to get the title, the content of the article and the date (even if I don't know how to manipulate the strings to get to this result). Can you help me? Make some code example please cause telling me "try to use arrayadapter" doesn't work too much xD

P.S.: I read an unthinkable number of tutorials, answers in this site etc. but nothing helped me…

Eric Finn
  • 8,629
  • 3
  • 33
  • 42
Leon
  • 665
  • 4
  • 10
  • 32
  • PHP advise: _mysql_ extension is deprecated as of PHP 5.5.0, and will be removed in the future. **Instead, the _MySQLi_ or _PDO_MySQL_ extension should be used**. Please read: [PHP: mysql_connect](http://us.php.net/manual/en/function.mysql-connect.php) Otherwise your PHP code is correct. You need some help in Java / Android development. – ChoiZ Apr 01 '14 at 14:37
  • Your data is coming back as a JSON, so you'll want to use [JSONObject](http://developer.android.com/reference/org/json/JSONObject.html) and [JSONArray](http://developer.android.com/reference/org/json/JSONArray.html) to help you use it. – nathansizemore Apr 01 '14 at 14:48
  • This is also a tutorial on using them [JSON into ListView Example](http://www.learn2crack.com/2013/11/listview-from-json-example.html) – nathansizemore Apr 01 '14 at 14:50
  • @LeonGuerrero read this and try to understand http://stackoverflow.com/a/12860046/913154 ;) – ChoiZ Apr 01 '14 at 15:09

1 Answers1

0

I know you don't want to hear it, but.... use an adapter. Here is a very in-depth tutorial with sample code.

http://www.vogella.com/tutorials/AndroidListView/article.html

KennyC
  • 593
  • 4
  • 12