亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將數據填充到 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 關注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號