2

<?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="com.example.day01.MainActivity">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rlv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>


</LinearLayout>


item


<?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"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/image_view"
        app:roundAsCircle="true"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="5dp"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="111111111"
        />
</LinearLayout>



item2

<?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"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/image_view"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="5dp"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="111111111"
        />
</LinearLayout>


main

package com.example.day01;


import android.database.Observable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;


import com.example.day01.bean.UserBean;
import com.example.day01.net.Api;
import com.example.day01.net.OkhttpUtils;
import com.example.day01.net.OnNetListener;
import com.google.gson.Gson;


import java.util.List;


import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class MainActivity extends AppCompatActivity {


    private RecyclerView mRlv;
    private MyAdapter2 myAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        OkhttpUtils.getInstance().doGet(Api.LOGIN_URL, new OnNetListener() {


            private MyAdapter2 myAdapter2;


            @Override
            public void onSuccess(String result) {
                UserBean userBean = new Gson().fromJson(result, UserBean.class);
                List<UserBean.StoriesBean> stories = userBean.getStories();
                mRlv.setLayoutManager(new LinearLayoutManager(MainActivity.this));
                myAdapter2 = new MyAdapter2(MainActivity.this, stories);
                mRlv.setAdapter(myAdapter2);
            }


            @Override
            public void onFailed(Exception e) {


            }
        });
    }


    private void initView() {
        mRlv = (RecyclerView) findViewById(R.id.rlv);
    }
}



MyAdapter2



package com.example.day01;


import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.example.day01.bean.UserBean;
import com.facebook.drawee.view.SimpleDraweeView;


import java.util.List;


/**
 * Created by Administrator on 2018/5/9.
 */


public class MyAdapter2 extends RecyclerView.Adapter<MyAdapter2.MyViewHolder> {
    private Context context;
    private List<UserBean.StoriesBean> list;
    private LayoutInflater inflater;
    public MyAdapter2(Context context, List<UserBean.StoriesBean> list) {
        this.context = context;
        this.list = list;
        inflater=LayoutInflater.from(context);
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder;
        if (viewType==0){
            View view = inflater.inflate( R.layout.item, null);
            holder= new MyViewHolder(view);
        }else if (viewType==1){
            View view = inflater.inflate( R.layout.item2, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            holder= new MyViewHolder(view);
        } else {
            holder = null;
        }


        return holder;


    }


    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String s = list.get(position).getImages().get(0);
        Uri uri = Uri.parse(s);
        holder.simpleDraweeView.setImageURI(uri);
        holder.text.setText(list.get(position).getTitle());
    }


    @Override
    public int getItemCount() {


        return list.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {


        private final TextView text;
        private final SimpleDraweeView simpleDraweeView;


        public MyViewHolder(View view) {
            super(view);
            simpleDraweeView = view.findViewById(R.id.image_view);
            text = view.findViewById(R.id.text);


        }
    }
}


Myapp


package com.example.day01;


import android.app.Application;


import com.facebook.drawee.backends.pipeline.Fresco;


/**
 * Created by Administrator on 2018/5/9.
 */


public class Myapp extends Application{
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}


bean


package com.example.day01.bean;


import java.util.List;


/**
 * Created by Administrator on 2018/5/9.
 */


public class UserBean {
    /**
     * date : 20180509
     * stories : [{"images":["https://pic4.zhimg.com/v2-cb1218d5947e60be39df4ce9f2a8c4b7.jpg"],"type":0,"id":9681981,"ga_prefix":"050908","title":"「你都 20 好几的男人了还天天打游戏,真没出息」"},{"images":["https://pic3.zhimg.com/v2-0a82314c26a546ab0e2591d65494ba96.jpg"],"type":0,"id":9681931,"ga_prefix":"050907","title":"港股迎来 20 年来最大变革,A 股恐怕又要因此再失去一波公司"},{"images":["https://pic2.zhimg.com/v2-cd3128cc82ee7330c4b19d1fc20301c1.jpg"],"type":0,"id":9681999,"ga_prefix":"050907","title":"马化腾张一鸣朋友圈「互怼」,看来头条和腾讯一战是在所难免了"},{"images":["https://pic2.zhimg.com/v2-6a5e13826658386270a9d2c559811e95.jpg"],"type":0,"id":9682062,"ga_prefix":"050906","title":"瞎扯 · 如何正确地吐槽"}]
     * top_stories : [{"image":"https://pic4.zhimg.com/v2-bf2189b8bad4ca7b78abf349c2497183.jpg","type":0,"id":9681999,"ga_prefix":"050907","title":"马化腾张一鸣朋友圈「互怼」,看来头条和腾讯一战是在所难免了"},{"image":"https://pic1.zhimg.com/v2-c00667590f4fd4b739e6904379a23768.jpg","type":0,"id":9681981,"ga_prefix":"050908","title":"「你都 20 好几的男人了还天天打游戏,真没出息」"},{"image":"https://pic2.zhimg.com/v2-f25b047abda14637c43dae6aee8c4969.jpg","type":0,"id":9681931,"ga_prefix":"050907","title":"港股迎来 20 年来最大变革,A 股恐怕又要因此再失去一波公司"},{"image":"https://pic3.zhimg.com/v2-85a1504d4b97991c4a24396d1451a482.jpg","type":0,"id":9681797,"ga_prefix":"050817","title":"你自以为无大碍的举动,可能每天都在伤害孩子的安全感"},{"image":"https://pic2.zhimg.com/v2-06476a270303260b60f74d676e43ada9.jpg","type":0,"id":9681902,"ga_prefix":"050812","title":"虚假的「马化腾回应」刷了屏,是谁制造了中文互联网史上最大的乌龙事件?"}]
     */


    private String date;
    private List<StoriesBean> stories;
    private List<TopStoriesBean> top_stories;


    public String getDate() {
        return date;
    }


    public void setDate(String date) {
        this.date = date;
    }


    public List<StoriesBean> getStories() {
        return stories;
    }


    public void setStories(List<StoriesBean> stories) {
        this.stories = stories;
    }


    public List<TopStoriesBean> getTop_stories() {
        return top_stories;
    }


    public void setTop_stories(List<TopStoriesBean> top_stories) {
        this.top_stories = top_stories;
    }


    public static class StoriesBean {
        /**
         * images : ["https://pic4.zhimg.com/v2-cb1218d5947e60be39df4ce9f2a8c4b7.jpg"]
         * type : 0
         * id : 9681981
         * ga_prefix : 050908
         * title : 「你都 20 好几的男人了还天天打游戏,真没出息」
         */


        private int type;
        private int id;
        private String ga_prefix;
        private String title;
        private List<String> images;


        public int getType() {
            return type;
        }


        public void setType(int type) {
            this.type = type;
        }


        public int getId() {
            return id;
        }


        public void setId(int id) {
            this.id = id;
        }


        public String getGa_prefix() {
            return ga_prefix;
        }


        public void setGa_prefix(String ga_prefix) {
            this.ga_prefix = ga_prefix;
        }


        public String getTitle() {
            return title;
        }


        public void setTitle(String title) {
            this.title = title;
        }


        public List<String> getImages() {
            return images;
        }


        public void setImages(List<String> images) {
            this.images = images;
        }
    }


    public static class TopStoriesBean {
        /**
         * image : https://pic4.zhimg.com/v2-bf2189b8bad4ca7b78abf349c2497183.jpg
         * type : 0
         * id : 9681999
         * ga_prefix : 050907
         * title : 马化腾张一鸣朋友圈「互怼」,看来头条和腾讯一战是在所难免了
         */


        private String image;
        private int type;
        private int id;
        private String ga_prefix;
        private String title;


        public String getImage() {
            return image;
        }


        public void setImage(String image) {
            this.image = image;
        }


        public int getType() {
            return type;
        }


        public void setType(int type) {
            this.type = type;
        }


        public int getId() {
            return id;
        }


        public void setId(int id) {
            this.id = id;
        }


        public String getGa_prefix() {
            return ga_prefix;
        }


        public void setGa_prefix(String ga_prefix) {
            this.ga_prefix = ga_prefix;
        }


        public String getTitle() {
            return title;
        }


        public void setTitle(String title) {
            this.title = title;
        }
    }
}


net



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值