I have this JSON result below from an Android request
[{"j_id":"1","j_title":"Online Content Management"},{"j_id":"2","j_title":"Graduate developer"}]
I am trying to display both the j_id
and j_title
columns values on each Listview
but I realized that the Listview
is only displaying the last record on every list.
This is the screenshot of my output
This is my Activity Code
txt1 = (TextView) findViewById(R.id.textView1);
txt2 = (TextView) findViewById(R.id.textView2);
listView = (ListView) findViewById(R.id.list);
list = new ArrayList<HashMap<String, String>>();
String[] from={"j_id","j_title"};//string array
int[] to={R.id.textView3,R.id.textView4}; //int array of views id's
dataAdapter = new SimpleAdapter(this,list,R.layout.list_view_items,from,to);//Create object and set the parameters for simpleAdapter
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
My doInBackground code in the AsyncTask class
@SuppressLint("NewApi")
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String, String>();
// parse json data
data.put("jobsbycategory", params[0]);
String result = ruc.sendPostRequest(URL2, data);
Log.v("Result value", result);
// parse json data
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsonObject = jArray.getJSONObject(i);
hashMap.put("j_id",jsonObject.getString("j_id"));
hashMap.put("j_title",jsonObject.getString("j_title")+"");
list.add(hashMap);//add the hashmap into arrayList
// add interviewee name to arraylist
//list2.add(jsonObject.getString("j_title"));
}
} catch (JSONException e) {
e.printStackTrace();
}
return result;
}
protected void onPostExecute(String s) {
loading.dismiss();
//list.add(hashMap);
dataAdapter.notifyDataSetChanged();
intent = getIntent();
jobsbycategory = intent.getStringExtra("jobsbycategory");
txt2.setText("Job Sector: " + " " + jobsbycategory );
Toast.makeText(getApplicationContext(), jobsbycategory, Toast.LENGTH_SHORT).show();
}
Every support is appreciated.