Android 用多个异步http请求填充Listview——loopj?

Android 用多个异步http请求填充Listview——loopj?,android,asynchronous,android-listview,loopj,listview-adapter,Android,Asynchronous,Android Listview,Loopj,Listview Adapter,TLDR: 我需要做的是发出多个异步HTTP请求,并使用数据填充列表视图——如果需要,我愿意接受一种全新的方法 嗨,我是android新手,我正在尝试使用Loopj的异步http客户端库。我已经按照他建议的方式实现了客户端,我正在检索数据,没有问题。我的问题是将处理程序的onSuccess中的数据返回到我要用于listview适配器的数据集 我读了不少书;在stackoverflow和其他源上。与我找到的大多数解决方案不同的是,在设置适配器之前,我必须发出多个http请求 我的适配器的数据源是我

TLDR: 我需要做的是发出多个异步HTTP请求,并使用数据填充列表视图——如果需要,我愿意接受一种全新的方法

嗨,我是android新手,我正在尝试使用Loopj的异步http客户端库。我已经按照他建议的方式实现了客户端,我正在检索数据,没有问题。我的问题是将处理程序的onSuccess中的数据返回到我要用于listview适配器的数据集

我读了不少书;在stackoverflow和其他源上。与我找到的大多数解决方案不同的是,在设置适配器之前,我必须发出多个http请求

我的适配器的数据源是我实现的自定义类型的数组,即ScoutProfile。 旁注:如果我对数据集的值进行硬编码,一切正常

在使用虚拟数据执行请求之前,我尝试过设置适配器。将适配器数据集换出更新的阵列。调用notifyDataSetChanged和invalidateViews

如果我没有初始化数组,我会得到一个空异常onSuccess中的更改没有生效。如果我实例化它-这意味着我使用notifyDataSetChanged-UI永远不会更新

我也尝试过runOnUIThread方法

以下是我的片段中的代码:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_scoutprofile, container, 
                                                                               false);
    RiotApiClient client = new RiotApiClient();
    profiles = new ScoutProfile[ids.length];

    mListView = (AbsListView) view.findViewById(android.R.id.list);

            final IntWrapper count = new IntWrapper(0);
    for(int j = 0; j < ids.length; j++) {
        final int index = j;
        String url = String.format("/api/lol/na/v2.3/league/by-summoner/%d/entry?", 
                                                                               ids[j]);
        client.get(url, null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String r) {
                try {
                    JSONArray response = new JSONArray(r);
                    for (int i = 0; i < response.length(); i++) {
                        JSONObject profile = response.getJSONObject(i);
                        if (profile.get("queueType") == "RANKED_SOLO_5x5") {
                            profiles[index] = new 
    ScoutProfile(profile.getString("playerOrTeamName"), "Silver", "Silver", "n/a", 40);
                            Log.e("ScoutProfileFragment", profiles[index].getName());
                            i = response.length();
                        }
                    }
                    count.integer += 1;
                    Log.e("ScoutProfileFragment", Integer.toString(count.integer));
                    if(count.integer == ids.length)
                    {
                        setUpAdapter(view);
                    }

                } catch (Exception ex) {

                }

            }
        });
    }
    return view;
}
我确信我没有包含的代码:ScoutProfile.java、ScoutProfileAdapter.java、RiotApiClient等都不是问题所在,但如果有人请求,我会将其添加到我的问题中

编辑: 我的意思是在片段代码中包含这一点:

public void setUpAdapter(View view)
{
    Log.e("ScoutProfileFragment", "setUpAdapter");
    mAdapter = new ScoutProfileAdapter(view.getContext(), profiles);
    ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
}