public void send() { ApiUtils.post( ApiUtils.TOPIC_NEW, new ApiParams() .with("node_id", node_id) .with("title", title.getText().toString()) .with("body", getBody()) .withToken(), new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { Toast.makeText(getActivity(), R.string.send_success, Toast.LENGTH_SHORT).show(); Topic t = gson.fromJson(response, Topic.class); Intent i = new Intent(getActivity(), TopicTabActivity.class); i.putExtra("topic_id", t.id); getActivity().startActivity(i); getActivity().finish(); } @Override public void onFailure(java.lang.Throwable error, java.lang.String response) { try { String s1 = JsonUtils.getString(new JSONObject(response), "error"); Toast.makeText( getActivity(), s1.replace(",", "\n").replace("\"", "").replace("[", ""), Toast.LENGTH_SHORT) .show(); } catch (JSONException e) { e.printStackTrace(); } } }); }
private void loadData(final int page) { ApiUtils.get( url, new ApiParams().with("page", page + "").with("per_page", "15"), new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { mLoadingFooter.setState(LoadingFooter.State.Idle, 3000); List<Topic> ts = gson.fromJson(response, listType); if (page == 1) { topics.clear(); mSwipeRefreshLayout.setRefreshing(false); UserUtils.cacheTopic(response, type); } for (Topic t : ts) { topics.add(t); } mAdapter.notifyDataSetChanged(); mLoadingFooter.setState(LoadingFooter.State.TheEnd); } }); }