为了账号安全,请及时绑定邮箱和手机立即绑定

将数据填充到 Listview 但 Arrayadapter 不起作用

将数据填充到 Listview 但 Arrayadapter 不起作用

HUH函数 2023-10-19 21:17:54
我正在尝试将数据从我的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());                }到处都找不到解决办法
查看完整描述

1 回答

?
千万里不及你

TA贡献1784条经验 获得超9个赞

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

问题是您将其作为第一个参数传递,以便为适配器提供上下文。

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

Solution

而不是这个通行证this

getContext() or getActivity()

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


查看完整回答
反对 回复 2023-10-19
  • 1 回答
  • 0 关注
  • 58 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信