How to get the results from Map in postExecute method of AsyncTask? I am not able to fetch results in results ?
@Override
protected void onPostExecute(Map<String,List<CommentModel>> results) {
super.onPostExecute(results);
for(int i=0;i<results.size();i++){
String ar =results.get(i).get(commentModelList);
// String content = commentModel.getContent();
Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_LONG).show();
ExpandableListAdapter expandableListAdapter = new Expandablelistadapter(getApplicationContext(),parentlist,childlist);
list.setAdapter(expandableListAdapter);
}
}
String ar =results.get(i).get(commentModelList);
should be changed to
CommentModel ar =results.get(commentModelList).get(i);
To avoid confusion is the future try to separate each step into a different line:
List<CommentModel> resultList = results.get(commentModelList);
CommentModel ar = resultList.get(i);
EDIT: Also, where are you closing your for loop? If I understand what you are trying to do in your code correctly, you want to iterate over the list that you get from your map not iterate over your map to get the list. So it should be more like:
List<CommentModel> resultList = results.get(commentModelList);
for(int i=0;i<resultList.size();i++){
CommentModel ar = resultList.get(i);
// use 'ar' in the rest of your code
}
来源:https://stackoverflow.com/questions/41810077/how-to-get-the-results-from-map-in-postexecute-method-of-asynctask