I have some trouble about this. So my problem is i want to put the result from json_encode into listview. Without long chit chat i'll show you this :
This is the result of json :
{
"length":
[
{
"kode_schedule":"sch0001",
"kode_matkul":"TIB01",
"title":"Basis Data",
"ruang":"501",
"latitude":"-6.18861653446272",
"longitude":"106.801122526546",
"lantai":"5",
"hari":"Selasa",
"jam":"17:45:00"
},
{
"kode_schedule":"sch0001",
"kode_matkul":"TIB02",
"title":"Pemrograman Berorientasi Objek",
"ruang":"LABB",
"latitude":"-6.18864706134991",
"longitude":"106.801161122636",
"lantai":"5",
"hari":"Selasa",
"jam":"19:30:00"
}
]
}
This is my code so far :
class GetLength extends AsyncTask<String, String, String> {
JSONParser jParser = new JSONParser();
protected String doInBackground(String... params) {
String title;
String ruang;
String lantai;
String hari;
String jam;
String latitude, longitude;
try {
// Building Parameters
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("username", txtNim.getText().toString()));
JSONObject json = jParser.makeHttpRequest("http://studentstracking.hol.es/installation.php", "POST", param);
JSONArray array = json.getJSONArray("length");
for (int i = 0; i < array.length(); i++) {
JSONObject row = array.getJSONObject(i);
kode_matkul = row.getString("kode_matkul");
title = row.getString("title");
ruang = row.getString("ruang");
latitude = row.getString("latitude");
longitude = row.getString("longitude");
lantai = row.getString("lantai");
hari = row.getString("hari");
jam = row.getString("jam");
kode_matkul_list.add(kode_matkul);
title_list.add(title);
ruang_list.add(ruang);
latitude_list.add(latitude);
longitude_list.add(longitude);
lantai_list.add(lantai);
hari_list.add(hari);
jam_list.add(jam);
array2d[] array2ds = new array2d[i];
array2ds[i] = new array2d(kode_matkul, title, ruang, longitude, latitude, lantai, hari, jam);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}
And this is the another class :
class array2d {
String kode_matkuls;
String titles;
String ruangs;
String lantais;
String haris;
String jams;
String latitudes, longitudes;
public array2d(String kode_matkuls, String titles, String ruangs, String longitudes, String latitudes, String lantais, String haris, String jams) {
this.kode_matkuls = kode_matkuls;
this.titles = titles;
this.ruangs = ruangs;
this.lantais = lantais;
this.haris = haris;
this.jams = jams;
this.latitudes = latitudes;
this.longitudes = longitudes;
}
}
And this is the method :
private void populate(ArrayList<String> array) {
ListView showList = (ListView) findViewById(R.id.listView2);
ArrayAdapter<String> shows = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_list_item_1, array);
showList.setAdapter(shows);
}
Anyone can fix this ? Or maybe there is other way to make it simple ? Just for simple, i want to that json show in listview.
Thanks for your cooperation