ChildAdapter.java
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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));
}
});
}
}
}