网易新闻APP

界面设计

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.<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值