課程
/移動(dòng)開發(fā)
/Android
/Android餅圖賬單案例開發(fā)
小白一只,我的project中為什么找不到j(luò)son啊
2018-04-10
源自:Android餅圖賬單案例開發(fā) 2-2
正在回答
自己寫一個(gè)工具類 public?class?Data?{ ????private?static?JSONArray?pieData; ????public?static?String?getPieData()?throws?JSONException?{ ????????if?(pieData?==?null)?{ ????????????synchronized?(Data.class)?{ ????????????????if?(pieData?==?null)?{ ????????????????????pieData?=?new?JSONArray(); ????????????????????HashMap<String,?Integer>?map1?=?new?HashMap<>(); ????????????????????map1.put("外賣",?34); ????????????????????map1.put("娛樂",?21); ????????????????????map1.put("其他",?45); ????????????????????pieData.put(getItem("2018年1月",?map1)); ????????????????????HashMap<String,?Integer>?map2?=?new?HashMap<>(); ????????????????????map2.put("外賣",?42); ????????????????????map2.put("娛樂",?65); ????????????????????map2.put("其他",?12); ????????????????????pieData.put(getItem("2018年2月",?map2)); ????????????????????HashMap<String,?Integer>?map3?=?new?HashMap<>(); ????????????????????map3.put("外賣",?34); ????????????????????map3.put("娛樂",?123); ????????????????????map3.put("其他",?24); ????????????????????pieData.put(getItem("2018年3月",?map3)); ????????????????????HashMap<String,?Integer>?map4?=?new?HashMap<>(); ????????????????????map4.put("外賣",?56); ????????????????????map4.put("娛樂",?45); ????????????????????map4.put("其他",?90); ????????????????????pieData.put(getItem("2018年4月",?map4)); ????????????????} ????????????} ????????} ????????return?pieData.toString(); ????} ????@SuppressLint("NewApi") ????private?static?JSONObject?getItem(String?date,?HashMap<String,?Integer>?map)?throws?JSONException?{ ????????JSONObject?obj?=?new?JSONObject(); ????????JSONArray?arr?=?new?JSONArray(); ????????Set<String>?set?=?map.keySet(); ????????String[]?keys?=?new?String[set.size()]; ????????set.toArray(keys); ????????for?(int?i?=?0;?i?<?keys.length;?i++)?{ ????????????JSONObject?object?=?new?JSONObject(); ????????????object.put("title",?keys[i]); ????????????object.put("value",?map.get(keys[i])); ????????????arr.put(object); ????????} ????????obj.put("date",?date); ????????obj.put("obj",?arr); ????????return?obj; ????} }
舉報(bào)
本教程手把手帶你打造酷炫對(duì)賬單效果,提升Android開發(fā)專業(yè)技能
1 回答使用PieChart報(bào)錯(cuò),找不到
2 回答為什么TextView textView=new TextView(getContext());中g(shù)etContext()下有錯(cuò)啊
3 回答return PieFragment.newInstance(position+""); 為什么我這個(gè)下面會(huì)有紅線
1 回答大家?guī)涂匆幌掳“?/p>
1 回答運(yùn)行出錯(cuò)是什么情況
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-05-13