文章目录
界面设计
1、网易新闻列表
2.、网易新闻详情
3、评论列表
4、我的收藏
网易新闻列表
网址 :https://api.apiopen.top/getWangYiNews
使用bejson网站的Json转实体类生产JsonRootBean和Result类型
JsonRootBean
/**
* Copyright 2021 bejson.com
*/
package com.example.demo;
import java.util.List;
/**
* Auto-generated: 2021-05-12 11:3:57
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class JsonRootBean {
private int code;
private String message;
private List<Result> result;
public void setCode(int code) {
this.code = code;
}
public int getCode() {
return code;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setResult(List<Result> result) {
this.result = result;
}
public List<Result> getResult() {
return result;
}
}
Result
/**
* Copyright 2021 bejson.com
*/
package com.example.demo;
import java.util.Date;
/**
* Auto-generated: 2021-05-12 11:3:57
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class Result {
private String path;
private String image;
private String title;
private String passtime;
public void setPath(String path) {
this.path = path;
}
public String getPath() {
return path;
}
public void setImage(String image) {
this.image = image;
}
public String getImage() {
return image;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setPasstime(String passtime) {
this.passtime = passtime;
}
public String getPasstime() {
return passtime;
}
}
新闻单行的布局文件news_item.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="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_news"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="新闻标题" />
<TextView
android:id="@+id/tv_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="新闻时间" />
</LinearLayout>
</LinearLayout>
适配器NewsAdapter
package com.example.demo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public class NewsAdapter extends BaseAdapter {
private Context context;
private List<Result> resultList;
public NewsAdapter(Context context, List<Result> resultList) {
this.context = context;
this.resultList = resultList;
}
@Override
public int getCount() {
return resultList.size();
}
@Override
public Object getItem(int position) {
return resultList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.news_item, parent, false);
}
// 新闻图片 标题 时间
ImageView iv_news = convertView.findViewById(R.id.iv_news);
TextView tv_title = convertView.findViewById(R.id.tv_title);
TextView tv_time = convertView.findViewById(R.id.tv_time);
Result result = resultList.<