将数据填充到 Listview 但 Arrayadapter 不工作

Populate Data to Listview but Arrayadapter not working

我正在尝试将数据从我的 arrayList 填充到列表视图。但由于某种原因,我收到错误 error: no suitable constructor found for ArrayAdapter(activity2.SendPostRequest,int,int,ArrayList<HashMap<String,String>>) constructor ArrayAdapter.ArrayAdapter(Context,int,int,HashMap<String,String>[]) is not applicable

                JSONArray json = new JSONArray(data);
                ArrayList<HashMap<String, String>>  arrayList = new ArrayList<HashMap<String, String>>();

                HashMap<String, String> map = new HashMap<String, String>();

                try {
                for(int i=0;i<json.length();i++){
                    JSONObject e =json.getJSONObject(i);

                    map.put("id", String.valueOf(i));
                    map.put("Name", "Vorname: " + e.getString("meta_value"));
                    map.put("orderid", "id: " + e.getString("post_id"));
                    arrayList.add(map);
                    return map.toString();
                }
                    ArrayAdapter<HashMap<String, String>> adapter = new ArrayAdapter<HashMap<String, String>>(this,android.R.layout.simple_list_item_1, android.R.id.text1, arrayList);

                list.setAdapter(adapter);
                }catch (JSONException e){
                    Log.e(this.getClass().getName(), "Some JSON error occurred" + e.getMessage());

                }

到处都找不到解决方案

ArrayAdapter(activity2.SendPostRequest,int,int,ArrayList>)

Problem is you pass this as the first parameter for giving context to the adapter.

constructor ArrayAdapter.ArrayAdapter(Context,int,int,HashMap<String,String>[])

Solution

而不是这一关this

getContext() or getActivity()

因为这可能指向不同的上下文,具体取决于您使用的是什么。

请参阅此 link 以深入了解 this 关键字