1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package com.example.scannrmobile; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.example.scannrmobile.HttpTask.HttpTaskHandler; import org.apache.http.client.methods.HttpGet; import org.json.JSONArray; import org.json.JSONException; import java.util.ArrayList; public class ScannrMobile extends Activity { private ListView mainListView ; private ArrayAdapter<String> listAdapter ; private ScannrMobile view; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mainListView = (ListView) findViewById( R.id.mainListView ); view = this; //DownloadWebPageTask task = new DownloadWebPageTask(); //task.execute(new String[] { "http://www.vogella.com" }); HttpTask task = new HttpTask(); task.setTaskHandler(new HttpTaskHandler() { public void taskSuccessful(JSONArray nodes) { // Just put the JSONObjects into an array list so we can use a ListAdapter ArrayList<String> data = new ArrayList(); // Ingest Data try { Log.d(this.getClass().getName(), "Total Nodes: "+nodes.length()); for (int i = 0; i < nodes.length(); i++ ) { data.add(nodes.getJSONObject(i).toString() ); } // TODO update the list } catch (JSONException j){ Log.e(this.getClass().getName(), j.getMessage()); } // Create ArrayAdapter using the planet list. listAdapter = new ArrayAdapter<String>(view, R.layout.simplerow, R.id.rowTextView, data); // Set the ArrayAdapter as the ListView's adapter. mainListView.setAdapter( listAdapter ); } public void taskFailed() { // handler failure (e.g network not available etc.) Log.e(this.getClass().getName(),"Task Failed"); } }); task.execute(new HttpGet("http://192.168.1.113/~maxious/scannr/calls.json.php?action=data")); } } |