<TextView
android:id=“@+id/joke_tv_title”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
android:text=“title”
android:textColor=“@android:color/black”
android:textSize=“18sp” />
<TextView
android:id=“@+id/joke_tv_content”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_margin=“5dp”
android:text=“content”
android:textColor=“@android:color/black”
android:textSize=“16sp” />
<ImageView
android:id=“@+id/joke_iv_content”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_margin=“5dp”
android:adjustViewBounds=“true”
android:scaleType=“fitXY” />
<TextView
android:id=“@+id/joke_tv_time”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_margin=“5dp”
android:gravity=“right”
android:text=“时间”
android:textSize=“14sp” />
上面的布局是每一个笑话内容显示的布局设计
4.创建一个json解析和数据收集的类
package com.lwz.conn;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
/**
-
这是一个数据解析的工具类,
-
-
这里是从源码中取出属性值
-
这里是使用从外到内一层一层的去获取资源数据,最里面一层的数据才是我们要显示在页面上的数据
-
这里的处理的方式是比较麻烦的一种,其中它处理的方式可以有好几种
-
这里的数据层层嵌套,就像xml资源的子标签一样
*/
/*下面是提供API网站给我们的数据的提示,xml文件中下面的某些变量,我们可以选择性的去使用,
但是这些变量的名字是固定的,更改了就获取不到了
allNum String 345 所有记录数
allPages String 45 所有页数。每页20条。
contentlist JokeItem[] 笑话条目内容
-
title String 吃了一百年的玉米 笑话标题
-
text String 笑话正文
-
ct String 2015-07-10 05:54:00.000 生成时间
currentPage String 1 当前第几页
maxResult String 20 每页最多显示几条*/
//因为要Intent来实现数据的传递,所以要实现序列化
public class JokeBean implements Serializable {
//最外层的属性值
int showapi_res_code;
String showapi_res_error;
Body showapi_res_body;//这个才是有用的信息数据,上面的实现其实也是可以不用去定义的
@Override
public String toString() {
return “JokeBean{” +
“showapi_res_body=” + showapi_res_body +