com.android.volley.Request.setTag()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中com.android.volley.Request.setTag方法的一些代码示例,展示了Request.setTag的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.setTag方法的具体详情如下:
包路径:com.android.volley.Request
类名称:Request
方法名:setTag

Request.setTag介绍

[英]Set a tag on this request. Can be used to cancel all requests with this tag by RequestQueue#cancelAll(Object).
[中]在此请求上设置标记。可用于通过RequestQueue#cancelAll(对象)取消所有带有此标记的请求。

代码示例

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
  public void onRefresh() {
    GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
      @Override
      public void onResponse(SectionCharacters characters) {
        mPageNum = 0;
        mAdapter.setList(characters.getCharacters(), characters.getSections().subList(0, mPageNum + 1));
        swipeToLoadLayout.setRefreshing(false);
      }
    }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError volleyError) {
        swipeToLoadLayout.setRefreshing(false);
        volleyError.printStackTrace();
      }
    });
    App.getRequestQueue().add(request).setTag(TAG + "refresh" + mType);
  }
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onLoadMore() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(SectionCharacters characters) {
      if (mPageNum < 3) {
        mPageNum++;
        mAdapter.append(characters.getSections().get(mPageNum).getCharacters());
      }else{
        Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
      }
      swipeToLoadLayout.setLoadingMore(false);
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setLoadingMore(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG+"loadmore");
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
  public void onLoadMore() {
    GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
      @Override
      public void onResponse(final SectionCharacters characters) {
        // here, I use post delay to show more animation, you don't have to.
        swipeToLoadLayout.postDelayed(new Runnable() {
          @Override
          public void run() {
            if (mPageNum < 3) {
              mPageNum++;
              mAdapter.append(characters.getSections().subList(mPageNum, mPageNum + 1));
            } else {
              Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
            }
            swipeToLoadLayout.setLoadingMore(false);
          }
        }, 2000);
      }
    }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError volleyError) {
        swipeToLoadLayout.setLoadingMore(false);
        volleyError.printStackTrace();
      }
    });
    App.getRequestQueue().add(request).setTag(TAG + "loadmore" + mType);
  }
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onRefresh() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(final SectionCharacters characters) {
      // here, I use post delay to show more animation, you don't have to.
      swipeToLoadLayout.postDelayed(new Runnable() {
        @Override
        public void run() {
          mPageNum = 0;
          mAdapter.setList(characters.getCharacters(), characters.getSections().subList(0, mPageNum + 1));
          swipeToLoadLayout.setRefreshing(false);
        }
      }, 3000);
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setRefreshing(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG + "refresh" + mType);
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onRefresh() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(SectionCharacters characters) {
      mAdapter.setList(characters.getSections().get(0).getCharacters());
      swipeToLoadLayout.setRefreshing(false);
      mPageNum = 0;
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setRefreshing(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG+"refresh");
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onLoadMore() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(SectionCharacters characters) {
      if (mPageNum < 3) {
        mPageNum++;
        mAdapter.append(characters.getSections().subList(mPageNum, mPageNum + 1));
      } else {
        Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
      }
      swipeToLoadLayout.setLoadingMore(false);
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setLoadingMore(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG + "loadmore" + mType);
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onRefresh() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(SectionCharacters sectionCharacters) {
      List<Character> characters = sectionCharacters.getCharacters();
      for (int i = 0; i < characters.size(); i++) {
        String img = characters.get(i).getAvatar();
        if (i < ivArray.length) {
          Picasso.with(getActivity()).load(img).into(ivArray[i]);
        }
      }
      swipeToLoadLayout.setRefreshing(false);
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setRefreshing(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG);
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onRefresh() {
  GsonRequest request = new GsonRequest<SectionCharacters>(Constants.API.CHARACTERS, SectionCharacters.class, new Response.Listener<SectionCharacters>() {
    @Override
    public void onResponse(SectionCharacters characters) {
      mAdapter.setList(characters.getSections());
      if (viewPager.getAdapter() == null) {
        mPagerAdapter = new LoopViewPagerAdapter(viewPager, indicators);
        viewPager.setAdapter(mPagerAdapter);
        viewPager.addOnPageChangeListener(mPagerAdapter);
        mPagerAdapter.setList(characters.getCharacters());
        viewPager.setBackgroundDrawable(getResources().getDrawable(R.mipmap.bg_viewpager));
      } else {
        mPagerAdapter = (LoopViewPagerAdapter) viewPager.getAdapter();
        mPagerAdapter.setList(characters.getCharacters());
      }
      swipeToLoadLayout.setRefreshing(false);
    }
  }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      swipeToLoadLayout.setRefreshing(false);
      volleyError.printStackTrace();
    }
  });
  App.getRequestQueue().add(request).setTag(TAG);
}

代码示例来源:origin: googolmo/OkVolley

@Override
public Request<?> setTag(Object tag) {
  return super.setTag(tag);
}

代码示例来源:origin: tazimete/android-app-food-delivery-system

public <T> void addToRequestQueue(Request<T> req, String tag) {
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  getRequestQueue().add(req);
}

代码示例来源:origin: navyifanr/AndroidTrainingDemo

public <T> void addToRequestQueue(Request<T> req, String tag) {
  // set the default tag if tag is empty
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  getRequestQueue().add(req);
}

代码示例来源:origin: msahakyan/nested-recycler-view

public <T> void addToRequestQueue(Request<T> req, String tag) {
  // set the default tag if tag is empty
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  getRequestQueue().add(req);
}

代码示例来源:origin: anyaudio/anyaudio-android-app

public <T> void addToRequestQueue(Request<T> req, String tag, Context context) {
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  baseContext = context;
  getRequestQueue(context).add(req);
}

代码示例来源:origin: myinnos/ImageSliderWithSwipes

public <T> void addToRequestQueue(Request<T> req, String tag) {
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  getRequestQueue().add(req);
}

代码示例来源:origin: lytsing/weibo

/**
 * Adds the specified request to the global queue using the Default TAG.
 *
 * @param req request
 */
public <T> void addToRequestQueue(Request<T> req) {
  // set the default tag if tag is empty
  req.setTag(TAG);
  getRequestQueue().add(req);
}

代码示例来源:origin: vipulasri/Artisto_capstone

public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
  }
}

代码示例来源:origin: anyaudio/anyaudio-android-app

public <T> void addToRequestQueue(Request<T> req) {
  req.setTag(TAG);
  getRequestQueue(baseContext).add(req);
}

代码示例来源:origin: navyifanr/AndroidTrainingDemo

public <T> void addToRequestQueue(Request<T> req) {
  req.setTag(TAG);
  getRequestQueue().add(req);
}

代码示例来源:origin: domoticz/domoticz-android

public static <T> void addToRequestQueue(Request<T> req, RequestQueue queue) {
    req.setTag(TAG);

    RetryPolicy retryPolicy = new DefaultRetryPolicy(socketTimeout,
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

    req.setRetryPolicy(retryPolicy);
    queue.add(req);
  }
}

代码示例来源:origin: hypertrack/hyperlog-android

public static <T> void addToRequestQueue(Context context, Request<T> req, String tag) {
  // set the default tag if tag is empty
  req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  req.setShouldCache(true);
  req.setRetryPolicy(new DefaultRetryPolicy(5000, 4, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  if (mRequestQueue == null)
    getRequestQueue(context);
  mRequestQueue.add(req);
}

相关文章