I have a Listview and I need to get the String values of each row when I click the List view.
This is my code
public void ListDrwaer() {
List<Map<String, String>> employeeList = new ArrayList<Map<String, String>>();
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.optJSONArray("lectureraccount");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String name = jsonChildNode.optString("lecturerName");
String code = jsonChildNode.optString("lecturerCode");
String outPut = name + " --- " + code;
employeeList.add(createEmployee("lecturer", outPut));
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error" + e.toString(),
Toast.LENGTH_SHORT).show();
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, employeeList,android.R.layout.simple_list_item_1,new String[] { "lecturer" }, new int[] { android.R.id.text1 });
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
String str = parent.getAdapter().getItem(position).toString();
System.out.println(str);
}});
}
I Managed to get output like this.
{lecturer=MAGESWARY A/P MUNIANDI --- C-MAGESWARY}
My Question is how to get output like this
C-MAGESWARY
Thats all. I am new in programming and not know much. Do i need to change my code completly. If it is, How? Thank you.
Aucun commentaire:
Enregistrer un commentaire