布局
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录注册界面"
android:layout_gravity="center"
android:textSize="20sp"
android:textColor="#000"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/name"
android:hint="用户名"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"/>
<EditText
android:id="@+id/pwd"
android:hint="密码"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>
<Button
android:background="#03A9F4"
android:text="登录"
android:textSize="20sp"
android:id="@+id/login"
android:layout_gravity="center"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
<Button
android:background="#FF5722"
android:text="注册"
android:textSize="20sp"
android:id="@+id/register"
android:layout_gravity="center"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
</LinearLayout>
<?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"
tools:context=".Main2Activity">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="@mipmap/ic_launcher_round"/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="这是标题"
android:layout_marginTop="45dp"
android:layout_toRightOf="@+id/iv"
android:layout_marginLeft="20dp"
android:textColor="#000"
/>
</RelativeLayout>
LIstener
package com.example.day1102homework.listener;
public interface MyListener {
void onOk(String ok);
void onError(String message);
}
可以设置进度条的
package com.example.day1102homework.listener;
public interface MyProgressListener {
void onError(String message);
void oonprogress(int progress);
void finish();
}
Model
一个接口
package com.example.day1102homework.model;
import com.example.day1102homework.listener.MyListener;
import com.example.day1102homework.listener.MyProgressListener;
import java.util.HashMap;
public interface Mymodel {
void get(String url, MyListener myListener);
void post(String url, HashMap<String,String> map, final MyListener myListener);
void download(String url, String path, MyProgressListener myProgressListener);
void upload(String url, String path, String servername,String type, final MyListener myListener);
}
一个类实现这个接口
package com.example.day1102homework.model;
import com.example.day1102homework.Myutils;
import com.example.day1102homework.listener.MyListener;
import com.example.day1102homework.listener.MyProgressListener;
import java.util.HashMap;
public class Model implements Mymodel {
@Override
public void get(String url, MyListener myListener) {
Myutils.getInstance().doget(url,myListener);
}
@Override
public void post(String url, HashMap<String, String> map, MyListener myListener) {
Myutils.getInstance().dopost(url,map,myListener);
}
@Override
public void download(String url, String path, MyProgressListener myProgressListener) {
Myutils.getInstance().dodowuload(url,path,myProgressListener);
}
@Override
public void upload(String url, String path, String servername, String type, MyListener myListener) {
Myutils.getInstance().upload(url,path,servername,type,myListener);
}
}
创建一个JavaBean
package com.example.day1102homework;
import java.util.List;
public class JavaBean {
/**
* code : 200
* msg : 成功!
* data : [{"type":"10","text":"穿袜子总是破洞,有木有跟我一样的脚","user_id":"23176996","name":"百思用户23176996","screen_name":"百思用户23176996","profile_image":"","created_at":"2019-11-03 15:32:02","create_time":null,"passtime":"2019-11-03 15:32:02","love":"73","hate":"10","comment":"7","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"10","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbda482c7ae7_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbda482c7ae7_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbda482c7ae7_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbda482c7ae7_1.jpg","width":"640","height":"852","tag":"","t":1572766322,"ding":"73","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"你这特么是谋杀啊\u2026\u2026\u200b","user_id":"22711216","name":"丰恺KING","screen_name":"丰恺KING","profile_image":"http://thirdwx.qlogo.cn/mmopen/vi_32/zHBbcruvQgD2hNv0UgK4luy95ibTKjT6uibibBEoXnxBrOwbVX1Jgxmr5iaZ8GOcSX7oFLtzafiaMN7wGDuQvjP1jbw/132","created_at":"2019-11-03 15:29:02","create_time":null,"passtime":"2019-11-03 15:29:02","love":"95","hate":"7","comment":"11","repost":"0","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1103/5dbe03bf76ed6_wpd.mp4","videotime":24,"original_pid":"0","cache_version":2,"playcount":"1390","playfcount":"367","cai":"7","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1103/5dbe03bf76ed6_wpd.jpg","width":"400","height":"640","tag":"","t":1572766142,"ding":"95","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"狗狗的一生其实听短暂,它是人类的过客,可人类是它的一生","user_id":"23129253","name":"木金车","screen_name":"木金车","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d74b855eee_mini.jpg","created_at":"2019-11-03 14:59:02","create_time":null,"passtime":"2019-11-03 14:59:02","love":"251","hate":"6","comment":"25","repost":"6","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"56781","theme_name":"情感社区","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1101/5dbc2af27e1a6_wpd.mp4","videotime":27,"original_pid":"0","cache_version":2,"playcount":"3808","playfcount":"236","cai":"6","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc2af27e1a6_wpd.jpg","width":"540","height":"960","tag":"","t":1572764342,"ding":"251","favourite":"0","top_cmt":null,"themes":null},{"type":"10","text":"新娘子:批瓜婆娘","user_id":"15704485","name":"成都李扯火","screen_name":"成都李扯火","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/31/5d41627a28fc3_mini.jpg","created_at":"2019-11-03 14:42:02","create_time":null,"passtime":"2019-11-03 14:42:02","love":"62","hate":"1","comment":"6","repost":"0","bookmark":"2","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"1","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a4691ae1.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a4691ae1.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a4691ae1.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a4691ae1.gif","width":"400","height":"213","tag":"","t":1572763322,"ding":"62","favourite":"2","top_cmt":null,"themes":null},{"type":"41","text":"结伴同行,不限男女","user_id":"23159255","name":"百思用户23159255","screen_name":"百思用户23159255","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/09/12/5d792c8122321_mini.jpg","created_at":"2019-11-03 14:29:02","create_time":null,"passtime":"2019-11-03 14:29:02","love":"118","hate":"9","comment":"21","repost":"2","bookmark":"4","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1102/5dbd71c2bbb87_wpd.mp4","videotime":15,"original_pid":"0","cache_version":2,"playcount":"2882","playfcount":"687","cai":"9","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1102/5dbd71c2bbb87_wpd.jpg","width":"608","height":"544","tag":"","t":1572762542,"ding":"118","favourite":"4","top_cmt":null,"themes":null},{"type":"41","text":"姐夫们 那个火猛","user_id":"23130735","name":"散落的雪人","screen_name":"散落的雪人","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d8a4be0889_mini.jpg","created_at":"2019-11-03 13:58:02","create_time":null,"passtime":"2019-11-03 13:58:02","love":"222","hate":"12","comment":"30","repost":"6","bookmark":"2","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58191","theme_name":"搞笑视频","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1102/5dbc9acd279d3_wpd.mp4","videotime":19,"original_pid":"0","cache_version":2,"playcount":"10006","playfcount":"910","cai":"12","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1102/5dbc9acd279d3_wpd.jpg","width":"540","height":"960","tag":"","t":1572760682,"ding":"222","favourite":"2","top_cmt":null,"themes":null},{"type":"10","text":"可爱又治愈的马卡龙便当🥞🍘🍥","user_id":"11348180","name":"黄羊-5","screen_name":"黄羊-5","profile_image":"http://qzapp.qlogo.cn/qzapp/100336987/F84EBB7B557F528F6716397504B0EAAC/100","created_at":"2019-11-03 13:52:01","create_time":null,"passtime":"2019-11-03 13:52:01","love":"57","hate":"2","comment":"5","repost":"0","bookmark":"1","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"123","theme_name":"美食频道","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"2","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe36d9cedf8_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe36d9cedf8_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe36d9cedf8_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe36d9cedf8_1.jpg","width":"750","height":"6514","tag":"","t":1572760321,"ding":"57","favourite":"1","top_cmt":null,"themes":null},{"type":"41","text":"吃剩的柚子皮不要丢掉,放在家中值钱又实用,一年轻松省下不少钱","user_id":"23134674","name":"遇见同桌的她","screen_name":"遇见同桌的她","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1da983ca10f_mini.jpg","created_at":"2019-11-03 13:28:02","create_time":null,"passtime":"2019-11-03 13:28:02","love":"70","hate":"2","comment":"3","repost":"1","bookmark":"3","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"8466","theme_name":"知识分享","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1101/5dbc4318eef6a_wpd.mp4","videotime":163,"original_pid":"0","cache_version":2,"playcount":"601","playfcount":"9","cai":"2","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc4318eef6a_wpd.jpg","width":"852","height":"480","tag":"","t":1572758882,"ding":"70","favourite":"3","top_cmt":null,"themes":null},{"type":"10","text":"一会儿就洗白于脑出血","user_id":"15704485","name":"成都李扯火","screen_name":"成都李扯火","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/31/5d41627a28fc3_mini.jpg","created_at":"2019-11-03 13:22:01","create_time":null,"passtime":"2019-11-03 13:22:01","love":"70","hate":"1","comment":"0","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"1","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a12c4e0c.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a12c4e0c.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a12c4e0c.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/03/5dbe4a12c4e0c.gif","width":"240","height":"320","tag":"","t":1572758521,"ding":"70","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"一直都很喜欢kfc的土豆泥🥔今天安排上","user_id":"23133393","name":"小亚","screen_name":"小亚","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1da0046eec1_mini.jpg","created_at":"2019-11-03 12:57:02","create_time":null,"passtime":"2019-11-03 12:57:02","love":"78","hate":"5","comment":"5","repost":"4","bookmark":"28","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"123","theme_name":"美食频道","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1101/5dbc26420770c_wpd.mp4","videotime":46,"original_pid":"0","cache_version":2,"playcount":"1008","playfcount":"173","cai":"5","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1101/5dbc26420770c_wpd.jpg","width":"720","height":"480","tag":"","t":1572757022,"ding":"78","favourite":"28","top_cmt":null,"themes":null},{"type":"10","text":"辣妈7哥又和小鲜肉\u201c谈恋爱\u201d了~","user_id":"23164013","name":"13357909009","screen_name":"13357909009","profile_image":"","created_at":"2019-11-03 12:52:01","create_time":null,"passtime":"2019-11-03 12:52:01","love":"71","hate":"20","comment":"5","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"20","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbd15ba9c5f3_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbd15ba9c5f3_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbd15ba9c5f3_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/02/5dbd15ba9c5f3_1.jpg","width":"480","height