Ejemplo n.º 1
0
  @Override
  public void onStart() {
    super.onStart();
    mAdapter = new ImageAdapter(VolleySingleton.getInstance(mContext).getImageLoader());

    mSwipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {

            // This method performs the actual data-refresh operation.
            // The method calls setRefreshing(false) when it's finished.
            requestData(mAdapter);
          }
        });
  }
Ejemplo n.º 2
0
  protected void requestData(final BaseAdapter imageAdapter) {
    // category num가 -1이면 전체 정보 가져오기
    // 그 외(0~3) 이면 해당되는 카테고리 정보만 가져온다
    JsonArrayRequest jsonArrayRequest =
        new JsonArrayRequest(
            Request.Method.GET,
            RequestUrl.GET_BEST_FROM + getSelectedCategory(),
            null,
            new Response.Listener<JSONArray>() {
              @Override
              public void onResponse(JSONArray jsonArray) {
                Gson gson = new Gson();
                writings = new ArrayList<Writing>();
                int size = jsonArray.length();
                mImageUrls = new String[size];
                for (int i = 0; i < size; i++) {
                  try {
                    writings.add(gson.fromJson(jsonArray.getString(i), Writing.class));
                  } catch (JSONException e) {
                    Log.e(TAG, "JSONException : " + e);
                  }
                }
                mListView.setAdapter(imageAdapter);

                mProgressBar.setVisibility(View.GONE);

                // Stop the refreshing indicator
                mSwipeRefreshLayout.setRefreshing(false);
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError volleyError) {
                Log.e(TAG, "VolleyError : " + volleyError);
              }
            });

    VolleySingleton.getInstance(mContext).addTodRequestQueue(jsonArrayRequest);
  }