資料庫離線快取展示資料專項練習(一)
阿新 • • 發佈:2018-12-12
資料庫離線快取展示資料專項練習
View view = inflater.inflate(R.layout.fragment2, container, false);
listView = view.findViewById(R.id.listview);
MyHelper helper = new MyHelper(MyApp.getContext());
SQLiteDatabase database = helper.getReadableDatabase();
cursor = database.query(“test”, null, null, null, null, null, null);
cursor.moveToNext();
//使用Gson
json=cursor.getString(cursor.getColumnIndex(“content”));
Gson gson = new Gson();
NewsBean newsBean = gson.fromJson(json, NewsBean.class);
List<NewsBean.DataBean> list = newsBean.getData();
//設定介面卡
adapter3 = new MyAdapter3(getActivity(), list);
listView.setAdapter(adapter3);
return view;