private void initView() { novelList = new ArrayList<Novel>(); novelAdapter = new NovelAdapter(novelList); btnBack = (Button) findViewById(R.id.btn_back); btnBack.setOnClickListener(onClickListener); pullToRefreshListView = (PullToRefreshListView) findViewById(R.id.lv_novel_list); pullToRefreshListView.setOnRefreshListener( new OnRefreshListener() { @Override public void onRefresh() { page = 1; getData(); } }); listView = pullToRefreshListView.getRefreshableView(); listView.setAdapter(novelAdapter); listView.setOnScrollListener(onScrollListener); }
private void parseData(String result) { try { JSONObject jsonObject = new JSONObject(result); totalCount = jsonObject.getJSONObject("data").getInt("totalCount"); String novelListString = jsonObject.getJSONObject("data").getString("novelList"); Type type = new TypeToken<List<Novel>>() {}.getType(); List<Novel> list = JsonUtil.json2Any(novelListString, type); if (page == 1) { novelList.clear(); } if (list != null) { novelList.addAll(list); pullToRefreshListView.onRefreshComplete(); dismissDialog(); isloading = false; novelAdapter.notifyDataSetChanged(); } } catch (JSONException e) { e.printStackTrace(); } }