Volley是什么?
Google I/O 大会上,Google 推出 Volley的一个网络框架
Volley适合什么场景?
Volley适合网络通信频繁操作,并能同时实现多个网络通信。
网络框架-Volley网上很多,自己可以自行百度。我这就不提供了
1.Volley的使用解析Json
做一个简单有趣的小软件,一个QQ测凶吉的小软件,使用Volley解析一段地址获取Json并且解析Json显示出来,很简单,也很基础,不过却很直观!
先来看看效果图吧!
步骤
1.申请地址已经key
2.把Volley的jar文件导入工程
3.解析地址获取到json
4.解析json填入
1.申请的Key:8d9160d4a96f2a6b5316de5b9d14d09d
2.接口地址(聚合数据申请的):http://japi.juhe.cn/qqevaluate/qq?key=你申请的Key&qq=374960286
3.将Volley导入工程
4.开工了
注意一定要先添加网络权限: android:name=”android.permission.INTERNET”/>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.myapplication.MainActivity">
<RelativeLayout
android:id="@+id/tab1_rl"
android:layout_width="match_parent"
android:layout_height="51dp"
android:background="#088af7">
<TextView
android:layout_width="wrap_content"
android:layout_height="51dp"
android:layout_centerHorizontal="true"
android:background="@null"
android:gravity="center"
android:text="QQ测凶吉"
android:textColor="@android:color/white"
android:textSize="20dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="请输入你的QQ号码查询测试结果" />
<EditText
android:id="@+id/medittext"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_margin="10dp"
android:background="#f7f7f7"
android:gravity="center"
android:hint="请输入正确的QQ号" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/mbut"
android:layout_width="0dp"
android:layout_height="wrap_content"
andro