i wanna retrieve map(ArrayList) according to the key, help me with the code below
public class MainActivity extends AppCompatActivity {
Map<String,ArrayList<Model>> map=new ArrayMap<>(); <----
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
.....
for (int j=0;j<jsonArray.length();j++)
{
JSONObject tempObj=jsonArray.getJSONObject(j);
String price =tempObj.getString("price");
String product=tempObj.getString("Product");
String qty=tempObj.getString("Qty");
modelList.add(new Model(id,price,product,qty,date));
map.put(key,modelList); <----
modelList.clear();
}
......
......
//here to retrieve that map in the same mainactivity
CODE....??????? <----
here is my json where those months are dynamic (jan, april, jun,...they are not constant).
{
"response": "success",
"servicecode": "134",
"forecast": {
"month": {
"jan": [
{
"id": "1",
"price": "12",
"Product": "1086",
"Qty": "14"
},
{
"id": "2",
"price": "19",
"Product": "1746",
"Qty": "45"
}
],
"april": [
{
"id": "3",
"price": "89",
"Product": "1986",
"Qty": "15"
},
{
"id": "1",
"price": "12",
"Product": "1086",
"Qty": "145"
}
],
"jun": [
{
"id": "81",
"price": "132",
"Product": "17086",
"Qty": "1445"
},
{
"id": "11",
"price": "132",
"Product": "10786",
"Qty": "1445"
}
]
}
},
"message": "Competitor Sales."
}
what i did is i took all the response separately with the key and stored in MAp, now what i want to do is to display the array in according to month in View pager. so tell me map'll do good or any alternative....