My problem is when I set this two array in one list I cant get proper value of this two array.
Below is my json response which I get from server.
User_Label_List is not always getting but Admin_Label_List array is common.
{
"User_Label_List": [
{
"iLabelID": "60",
"vLabel": "At Ground"
}
],
"Admin_Label_List": [
{
"iLabelID": "53",
"vLabel": "At School"
},
{
"iLabelID": "51",
"vLabel": "At Office"
},
{
"iLabelID": "52",
"vLabel": "At Work"
},
{
"iLabelID": "50",
"vLabel": "At None"
},
{
"iLabelID": "49",
"vLabel": "At Home"
}
]
}
and this my code.
try {
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray("Admin_Label_List");
labelarray = new ArrayList<LabelModel>();
for (int i = 0; i < jsonArray.length(); i++) {
labelModel = new LabelModel();
JSONObject labeljson = jsonArray.getJSONObject(i);
// lableList.put("iLabelID", labeljson.getString("iLabelID"));
// lableList.put("vLabel", labeljson.getString("vLabel"));
labelModel.setLabelId(labeljson.getString("iLabelID"));
labelModel.setLabelName(labeljson.getString("vLabel"));
labelarray.add(labelModel);
}
Log.e("length", "== "+jsonObject.length());
if (jsonObject.length() == 2) {
String arryName = jsonObject.names().getString(1);
if (arryName.equalsIgnoreCase("User_Label_List")) {
JSONArray userjsonArray = jsonObject.getJSONArray("User_Label_List");
userlabelarray = new ArrayList<LabelModel>();
for (int i = 0; i < userjsonArray.length(); i++) {
// userLabelModel = new UserLabelModel();
JSONObject labeljson = userjsonArray.getJSONObject(i);
// lableList.put("iLabelID", labeljson.getString("iLabelID"));
// lableList.put("vLabel", labeljson.getString("vLabel"));
labelModel.setLabelId(labeljson.getString("iLabelID"));
labelModel.setLabelName(labeljson.getString("vLabel"));
userlabelarray.add(labelModel);
}
// userlabelarray.addAll(labelarray);
}
List<LabelModel> union = new ArrayList<LabelModel>(labelarray);
union.addAll(userlabelarray);
customeLabelAdpater = new CustomeLabelAdpater(ChooselabelActivity.this, lableList);
listView.setAdapter(customeLabelAdpater);
}
so can any one suggest me how can I achieve this?
You are not initializing your
LabelModelin second time, while you are filling your second array data, Can you please reinitialize yourLabelModel,don’t worry about previous data you already filled, so while filling next array data you have to reinitialize your
LabelModel, hope it will work.