【发布时间】:2015-09-14 08:44:32
【问题描述】:
我有异步任务,我从服务器获取 JSONArray 格式的数据。我想将该数据保存在共享首选项中并在列表视图中显示。我正在使用适配器。 我试过了,但没有得到任何东西
JSONArray arr = new JSONArray(strServerResponse);
JSONObject jsonObj = arr.getJSONObject(0);
for (int i = 0; i < arr.length(); i++) {
pojo = new Pojo();
JSONObject jobj2 = arr.getJSONObject(i);
String tipoftheday = jobj2.optString("tipsoftheday");
ArrayList<String> tii = new ArrayList<String>();
tii.add(tipoftheday);
}
今天的这个提示包含多个数据,我想将它们保存在共享首选项中,然后显示在列表视图中。 pojo 是一个我定义了 setter 和 getter 的类。
ArrayList<Pojo> tips;
tips = new ArrayList<Pojo>();
pojo.setTip(mydatafromsharedprefernces);
tips.add(pojo);
tipsAdapter = new TipsAdapter(TipsActivity.this, tips);
listTips.setAdapter(tipsAdapter);
如何在共享首选项中添加数据。谁能帮帮我。
【问题讨论】:
-
最好将 JSON 数据转换为字符串并存储在一个共享首选项中。