ChildAdapter.java 1.97 KB
package com.shunzhi.parent.adapter;


import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.share.mvpsdk.base.adapter.BaseRecyclerViewAdapter;
import com.share.mvpsdk.base.adapter.BaseRecyclerViewHolder;
import com.shunzhi.parent.R;
import com.shunzhi.parent.bean.ChildBean;
import com.shunzhi.parent.ui.activity.ChildDetialActivity;

/**
 * Created by Administrator on 2018/3/9 0009.
 */

public class ChildAdapter extends BaseRecyclerViewAdapter<ChildBean> {

    Context context;

    public ChildAdapter(Context context) {
        this.context = context;
    }


    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_childlist, null);
        return new MyViewHolder(view);
    }

    private class MyViewHolder extends BaseRecyclerViewHolder<ChildBean> {

        TextView txt_childname, txt_childclass;


        public MyViewHolder(View view) {
            super(view);
            txt_childname = view.findViewById(R.id.txt_childname);
            txt_childclass = view.findViewById(R.id.txt_childclass);
        }

        @Override
        public void onBindViewHolder(final ChildBean object, int position) {
            txt_childname.setText(object.getStudentName());
            txt_childclass.setText(object.getSchoolName() + "    " + object.getClassName());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Gson g = new Gson();
                    String jsonString = g.toJson(object, ChildBean.class).toString();
                    context.startActivity(new Intent().putExtra("childJson", jsonString).setClass(context, ChildDetialActivity.class));
                }
            });
        }

    }
}