zoukankan      html  css  js  c++  java
  • Volley框架模式

    Volley-GET

    import com.android.volley.toolbox.Volley;
    
    
    public class JDKActivity extends AppCompatActivity {
    
        EditText et1;
        RequestQueue requestQueue;
        //请求队列
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_jdk);
            et1=(EditText)findViewById(R.id.et1);
            //创建Volley的请求队列
            //在子线程
            requestQueue = Volley.newRequestQueue(this);
        }
        //Volley-GET
        public void bt_3(View v)
        {
            //1-启动进度对话框
            final ProgressDialog pd = ProgressDialog.show(this,null,"请稍后……");
    
            //构建StringRequest
            StringRequest sr=new StringRequest("http://192.168.0.164:81/index.asp?name=Volley&password=456",
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String s) {
                            //处理正常响应
                            //在主线程里运行
                            et1.setText(s);
                            pd.dismiss();
                        }
                    },
                    new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    //处理异常响应
                    pd.dismiss();
                    Toast.makeText(JDKActivity.this, "响应异常   响应状态码"+volleyError.networkResponse.statusCode, Toast.LENGTH_SHORT).show();
                }
            });
            //加入队列
            requestQueue.add(sr);
        }
    View Code

    Volley-POST

     //Volley-POST
        public void bt_4(View v)
        {
            //1-启动进度对话框
            final ProgressDialog pd = ProgressDialog.show(this,null,"请稍后……");
    
            //构建StringRequest
            StringRequest sr=new StringRequest(Request.Method.POST,"http://192.168.0.164:81/index.asp",
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String s) {
                            //处理正常响应
                            //在主线程里运行
                            et1.setText(s);
                            pd.dismiss();
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                            //处理异常响应
                            pd.dismiss();
                            Toast.makeText(JDKActivity.this, "响应异常   响应状态码"+volleyError.networkResponse.statusCode, Toast.LENGTH_SHORT).show();
                        }
                    }){
                //重写得到参数的方法
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String,String> rtn=new HashMap<>();
                    rtn.put("name","postvolley");
                    rtn.put("password","567");
                    return rtn;
                }
            };
            //加入队列
            requestQueue.add(sr);
        }
    View Code

  • 相关阅读:
    使用淘宝Str2varlist与str2numlist 代替 in/exist ,提升性能(Oracle)
    由浅入深理解索引的实现
    你知道数据库索引的工作原理吗?
    深入理解数据库磁盘存储(Disk Storage)
    如何解析oracle执行计划
    Beyond Compare 4 最新中文版 注册码 key
    并发和并行的区别
    代码复用的规则
    Some Java exceptions, messages and errors.
    菜鸟学SSH(十六)——Struts2内部是如何工作的
  • 原文地址:https://www.cnblogs.com/1ming/p/5586221.html
Copyright © 2011-2022 走看看