如何从AsyncTask的postExecute方法中的Map获取结果? [英] How to get the results from Map in postExecute method of AsyncTask ?

查看:68
本文介绍了如何从AsyncTask的postExecute方法中的Map获取结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从AsyncTask的postExecute方法中的Map获取结果?我无法从结果中获取结果吗?

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);

应更改为

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);

另外,您在哪里关闭for循环?如果我正确理解了您要在代码中执行的操作,则希望遍历从地图获得的列表,而不要遍历地图以获取列表.所以应该更像是:

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
}

这篇关于如何从AsyncTask的postExecute方法中的Map获取结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆