First of all I use volley library for my post request. In this case I retrieve as response from the server the following json format.
{"status":"success","message":"Teams without a league have been
found.",
"teams":[{"ID":"31","team_name":"A Team"},
{"ID":"101","team_name":"The BEST team"},
{"ID":"109","team_name":"ael fc"},
{"ID":"110","team_name":"UK"},
{"ID":"111","team_name":"cyprus"},
{"ID":"112","team_name":"biochemisty"}
]
}
I do all the necessaray JSON deserialization and dispay the objects of the team array in a list.
Now what I want to do is to store in a String array the ID values of the selected teams. Any ideas on that?
Here is the part of the code
final JsonObjectRequest jsonObjReq1 = new
JsonObjectRequest(AppConfig.URL_GET_ALL_LEAGUE_TEAMS, jsonObject,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", response.toString());
try {
if(response.getString("status").equals("success")){
JSONArray teamsArray = response.getJSONArray("teams");
for(int i = 0; i< teamsArray.length(); i++){
teams = teamsArray.getJSONObject(i);
noLeagueMembersClass = new
NoLeagueMemberClass();
noLeagueMembersClass.
setTeamMember(teams.getString("team_name"));
noLeagueMembersClass.
setTeamMember(teams.getString("ID"));
noLeagueMemberList.add(noLeagueMembersClass);
listView.setAdapter(noLeagueAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);
listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick
(AdapterView<?> parent, View view, int position, long id){
Toast.makeText(getApplicationContext(),"You
clicked"+position,Toast.LENGTH_SHORT).show();
}
});
}
}
} catch (JSONException e) {
e.printStackTrace();
}
I try the following
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
try {
final String teamId =
teams.getString("ID");
Log.d("teamId",teamId);
} catch (JSONException e) {
e.printStackTrace();
}
}
but I always get teamId=120. For example when I select first row,I want teamId to be equals with 31. When I click the second row I want the teamId to be equal with 101 and so on. I don't want to pass any values to a next activity yet. I hope the following picture will get you to understand what I want to do.
In other words I want each click I do to correspond to the JSON table.