Java Code Examples for com.android.volley.toolbox.StringRequest#setTag()

The following examples show how to use com.android.volley.toolbox.StringRequest#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindListFragment.java    From school_shop with MIT License 6 votes vote down vote up
private void loadData() {
	stringRequest = new StringRequest(URLs.MARK_LIST, new Response.Listener<String>() {

		@Override
		public void onResponse(String response) {
			parseJson(response);
		}
	}, new Response.ErrorListener() {

		@Override
		public void onErrorResponse(VolleyError error) {
			showToastError(error.toString());
		}
	});
	
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 2
Source File: GoodsDetailActivity.java    From school_shop with MIT License 6 votes vote down vote up
private void loadData(){
	stringRequest = new StringRequest(URLs.MARKET_COMMENTLIST_URL+goodsEntity.getId(), 
			new Response.Listener<String>() {

				@Override
				public void onResponse(String response) {
					jsonData = response;
					parseJson();
					goodsDetailAdapter.notifyDataSetChanged();
				}
			} , new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
				}
			});
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 3
Source File: ShareListFragment.java    From school_shop with MIT License 6 votes vote down vote up
private void loadData() {
	getActivity().runOnUiThread(new Runnable() {
		@Override
		public void run() {
			swipeRefreshLayout.setRefreshing(true);
		}
	});
	stringRequest = new StringRequest(URLs.SHARE_LIST, new Response.Listener<String>() {

		@Override
		public void onResponse(String response) {
			parseJson(response);
		}
	}, new Response.ErrorListener() {

		@Override
		public void onErrorResponse(VolleyError error) {
			showToastError(error.toString());
		}
	});
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 4
Source File: UPnPDiscovery.java    From android-upnp-discovery with MIT License 5 votes vote down vote up
private void getData(final String url, final UPnPDevice device) {
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    device.update(response);
                    mListener.OnFoundNewDevice(device);
                    devices.add(device);
                    mThreadsCount--;
                    if (mThreadsCount == 0) {
                        mActivity.runOnUiThread(new Runnable() {
                            public void run() {
                                mListener.OnFinish(devices);
                            }
                        });
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mThreadsCount--;
            Log.d(TAG, "URL: " + url + " get content error!");
        }
    });
    stringRequest.setTag(TAG + "SSDP description request");
    Volley.newRequestQueue(mContext).add(stringRequest);
}
 
Example 5
Source File: UPnPDiscovery.java    From android-upnp-discovery with MIT License 5 votes vote down vote up
private void getData(final String url, final UPnPDevice device) {
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    device.update(response);
                    mListener.OnFoundNewDevice(device);
                    devices.add(device);
                    mThreadsCount--;
                    if (mThreadsCount == 0) {
                        mActivity.runOnUiThread(new Runnable() {
                            public void run() {
                                mListener.OnFinish(devices);
                            }
                        });
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mThreadsCount--;
            Log.d(TAG, "URL: " + url + " get content error!");
        }
    });
    stringRequest.setTag(TAG + "SSDP description request");
    Volley.newRequestQueue(mContext).add(stringRequest);
}
 
Example 6
Source File: SearchGoodsActivity.java    From school_shop with MIT License 5 votes vote down vote up
private void initSearchList(String content) {
	loadingView.setVisibility(View.VISIBLE);
	progressBarTitle.setText(getStringByRId(R.string.hint_loading));
	jsonData = null;
	//解决url传值乱码问题
	content = Uri.encode(content);
	int position = spinner.getSelectedItemPosition();
	String url = null;
	if(position==0){
		url = URLs.SEARCH+"?s="+content+"&scId="+scId;
	}else {
		url = URLs.SEARCH+"?s="+content+"&lat="+lat+"&lont="+lont+"&type=location";
	}
	
	stringRequest = new StringRequest(url, 
			new Response.Listener<String>() {

				@Override
				public void onResponse(String response) {
					jsonData=response;
					parseJson();
					loadingView.setVisibility(View.GONE);
				}

			}, new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
					showToastError(error.toString());
					loadingView.setVisibility(View.GONE);
				}
			});
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 7
Source File: ChooseSchoolActivity.java    From school_shop with MIT License 5 votes vote down vote up
private void initSchoolList(String url) {
	jsonData = null;
	stringRequest = new StringRequest(url, 
			new Response.Listener<String>() {

				@Override
				public void onResponse(String response) {
					jsonData=response;
					parseJson();
					loadingLayout.setVisibility(View.GONE);
				}

			}, new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
					showToastError(error.toString());
					loadingLayout.setVisibility(View.GONE);
				}
			});
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 8
Source File: MarketListFragment.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 
 * @author Owater
 * @createtime 2015-3-24 下午5:59:09
 * @Decription 开始加载数据
 *
 * @param postion viewpager的位置,代表类别
 */
private void loadingData(int postion,int beforeId){
	jsonData = null;
	String userId = null;
	if(MyApplication.userInfo!=null){
		userId = MyApplication.userInfo[1];
	}
	String url = URLs.MARKET_GOODSLIST_URL+postion+"&beforeId="+beforeId+"&schoolId="+schoolId+"&userId="+userId;
	Log.i(TAG,"MARKET_GOODSLIST_URL=="+url);
	stringRequest = new StringRequest(url, 
			new Response.Listener<String>() {

				@Override
				public void onResponse(String response) {
					Log.i(TAG,"response=="+response);
					jsonData=response;
					parseJson();
					resetLoading();
				}
			}, new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
					showToastError(error.toString());
					mfooUpdate.showFail("加载失败,点击重新加载");
					resetLoading();
				}
			});
	stringRequest.setTag(stringRequestTag);
	requestQueue.add(stringRequest);
}
 
Example 9
Source File: VolleyRequest.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
public static void RequestGet(Context context,String url, String tag, VolleyInterface vif)
    {

        MyApplication.getHttpQueues().cancelAll(tag);
        stringRequest = new StringRequest(Request.Method.GET,url,vif.loadingListener(),vif.errorListener());
        stringRequest.setTag(tag);
        MyApplication.getHttpQueues().add(stringRequest);
        // 不写也能执行
//        MyApplication.getHttpQueues().start();
    }
 
Example 10
Source File: VolleyRequest.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
public static void RequestPost(Context context,String url, String tag,final Map<String, String> params, VolleyInterface vif)
    {
        MyApplication.getHttpQueues().cancelAll(tag);
        stringRequest = new StringRequest(Request.Method.POST,url,vif.loadingListener(),vif.errorListener())
        {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return params;
            }
        };
        stringRequest.setTag(tag);
        MyApplication.getHttpQueues().add(stringRequest);
        // 不写也能执行
//        MyApplication.getHttpQueues().start();
    }
 
Example 11
Source File: MainActivity.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
private void volley_get()
    {
        textview.setText("get 开始了");
        // 错误url:String url = "ip.taobao.com/service/getIpInfo.php?ip=202.96.128.166"
        String url = "http://ip.taobao.com/service/getIpInfo.php?ip=202.96.128.166";
        StringRequest request = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>()
                {
                    @Override
                    public void onResponse(String response) {
                        textview.setText(response);
//                        Toast.makeText(MainActivity.this,response, Toast.LENGTH_SHORT).show();
                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {
//                        Toast.makeText(MainActivity.this,error.toString(), Toast.LENGTH_SHORT).show();
                        textview.setText(error.toString());
                    }


                }
        );
        requestTag = "volley_get";
        request.setTag(requestTag);
        MyApplication.getHttpQueues().add(request);
    }
 
Example 12
Source File: MainActivity.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
private void volley_post()
    {
        textview.setText("post String 开始了");
        // 错误url:String url = "ip.taobao.com/service/getIpInfo.php?ip=202.96.128.166"
        String url = "http://ip.taobao.com/service/getIpInfo.php?";
        StringRequest request = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>()
                {
                    @Override
                    public void onResponse(String response) {
                        textview.setText(response);
//                        Toast.makeText(MainActivity.this,response, Toast.LENGTH_SHORT).show();
                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {
//                        Toast.makeText(MainActivity.this,error.toString(), Toast.LENGTH_SHORT).show();
                        textview.setText(error.toString());
                    }


                }
        ){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("ip", "202.96.128.166");
                return hashMap;
            }
        };

        requestTag = "volley_post";
        request.setTag(requestTag);
        MyApplication.getHttpQueues().add(request);
    }
 
Example 13
Source File: VolleyFragment.java    From jus with Apache License 2.0 5 votes vote down vote up
private void standardQueueStringRequest(View v) {
	final TextView mTextView = (TextView) v.findViewById(R.id.tv_string_request);

	// StringRequest with VOLLEY with Standard RequestQueue
	// Instantiate the RequestQueue.
	requestQueue = Volley.newRequestQueue(v.getContext());
	String url = "http://www.google.com";

	// Request a string response from the provided URL.
	StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
			new Response.Listener<String>() {
				@Override
				public void onResponse(String response) {
					// Display the first 500 characters of the response string.
					mTextView.setText("Response is: " + response.substring(0, 500));
				}
			}, new Response.ErrorListener() {
		@Override
		public void onErrorResponse(VolleyError error) {
			mTextView.setText("That didn't work!");
		}
	});

	stringRequest.setTag(TAG);
	// Add the request to the RequestQueue.
	requestQueue.add(stringRequest);
}
 
Example 14
Source File: ManagerCityActivity.java    From WayHoo with Apache License 2.0 5 votes vote down vote up
private void getWeather(City city) {
	if (city == null)
		return;
	int index = mTmpCitys.indexOf(city);
	mAdapter.setRefreshingIndex(index);// 开始刷新

	final String postID = city.getPostID();
	StringRequest sr = new StringRequest(
			String.format(WeatherSpider.WEATHER_ALL, postID),
			new Response.Listener<String>() {

				@Override
				public void onResponse(String response) {
					// sr.getTag();
					try {
						WeatherInfo weatherInfo = WeatherSpider
								.getWeatherInfo(mActivity, postID, response);
						if (!WeatherSpider.isEmpty(weatherInfo)) {
							save2Database(postID, response, weatherInfo);
							mTmpCitys = getTmpCities();
						}
					} catch (JSONException e) {

					}
					mAdapter.setRefreshingIndex(-1);// 重置
					updateRefreshMode(false);// 结束刷新
				}
			}, new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
					mAdapter.setRefreshingIndex(-1);// 重置
					updateRefreshMode(false);// 结束刷新
				}
			});
	sr.setTag(postID);
	App.getVolleyRequestQueue().add(sr);

}
 
Example 15
Source File: HttpTools.java    From volley with Apache License 2.0 4 votes vote down vote up
private void sendRequest(final int method, final RequestInfo requestInfo, final HttpCallback httpResult) {
    if (sRequestQueue == null) {
        sRequestQueue = Volley.newNoCacheRequestQueue(mContext);
    }
    if (httpResult != null) {
        httpResult.onStart();
    }
    if (requestInfo == null || TextUtils.isEmpty(requestInfo.url)) {
        if (httpResult != null) {
            httpResult.onError(new Exception("url can not be empty!"));
            httpResult.onFinish();
        }
        return;
    }
    switch (method) {
    case Request.Method.GET:
        requestInfo.url = requestInfo.getFullUrl();
        VolleyLog.d("get->%s", requestInfo.getUrl());
        break;
    case Request.Method.DELETE:
        requestInfo.url = requestInfo.getFullUrl();
        VolleyLog.d("delete->%s", requestInfo.getUrl());
        break;

    default:
        break;
    }
    final StringRequest request = new StringRequest(method, requestInfo.url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            if (httpResult != null) {
                httpResult.onResult(response);
                httpResult.onFinish();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) { 
            if (httpResult != null) {
                httpResult.onError(error);
                httpResult.onFinish();
            }
        }
    }, new Response.LoadingListener() {

        @Override
        public void onLoading(long count, long current) {
            if (httpResult != null) {
                httpResult.onLoading(count, current);
            }
        }
    }) {

        @Override
        public void cancel() {
            super.cancel();
            if (httpResult != null) {
                httpResult.onCancelled();
            }
        }
        
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            if (method == Request.Method.POST || method == Request.Method.PUT) {
                VolleyLog.d((method == Request.Method.POST ? "post->%s" : "put->%s"), requestInfo.getUrl() + ",params->" + requestInfo.getParams().toString());
                return requestInfo.getParams();
            } 
            return super.getParams();
        }
        
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return requestInfo.getHeaders();
        }
    };
    request.setTag(this);
    sRequestQueue.add(request);
}