Volley请求
来源:互联网 发布:mac桌面安装包 编辑:程序博客网 时间:2024/05/21 17:16
public class MainActivity extends AppCompatActivity { private EditText et ; private ProgressDialog dialog = null; private static final String MY_API_KEY = "362f70e78638efc3cc58370799e50883"; private TextView weather_content; String httpUrl = " http://apis.baidu.com/heweather/weather/free"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); weather_content = (TextView)findViewById(R.id.weather_content); et = (EditText)findViewById(R.id.edit_request); Button button = (Button)findViewById(R.id.button_search); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String city = et.getText().toString(); if (city.isEmpty()){ return; }else { String cityName = "city="+city; dialog = ProgressDialog.show(MainActivity.this,"请等待....","获取数据中....",true); netRequest(httpUrl+"?"+cityName); } } }); } private void netRequest(String datas ) { RequestQueue queue = Volley.newRequestQueue(this); Log.d("city=:",""+datas); JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, datas, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { dialog.dismiss(); weather_content.setText(jsonObject.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }){ @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String,String> mHeaders = new HashMap<>(); mHeaders.put("apikey",MY_API_KEY); return mHeaders; } }; queue.add(request); }}
0 0
- Volley请求
- Volley请求
- Volley请求
- Volley请求
- volley请求搭配图片请求
- volley请求数据(二)
- 网络请求框架---Volley
- android Volley JSON请求
- Volley网络请求框架
- Volley的Https请求
- volley JSON请求数据
- volley请求原理
- 网络请求框架---Volley
- 网络请求框架-Volley
- Volley发送StringRequest请求
- volley使用 POST请求
- Volley多次请求 RetryPolicy
- volley JSON请求数据
- webservice使用@Autowaired注入JDBCTemplate为NULL
- mysql 时间处理
- 浅谈 SQL 中的锁(五)另一种解决方案
- 半实物仿真动画入门
- UEFI启动-GPT分区,Windows 7+ 系统引导修复
- Volley请求
- css盒子模型创建网页布局
- JQuery选择器(一) 基本选择器
- struts2中数据校验
- 《C# 并发编程 · 经典实例》读书笔记
- mabatis有外键关联的情况下删除数据
- java反射机制简单应用
- VS2015 使用Mysql-connector/c++ 链接数据库(环境配置)
- ssh项目中strust2从2.0.11升级到2.3.15.1详细步骤