此篇博文是一个在项目中很常用,但是写起来却比较简单的demo,我已经优化过了代码~
实现效果
Effect 1 (只有左侧点击效果)
Effect 2 (双表联动)
Effect 3 (双表联动 - 与Effect2基本相近)
开发实战
在开发实战中主要用到了俩个三方框架 fastjson、BaseRecyclerViewAdapterHelper,故此需要加入以下依赖
build(Project)
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
build(Model)
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.alibaba:fastjson:1.1.54.android'
数据请求方式
- 一次性网络请求到所有数据,然后点击左侧tab分类后,自己过滤数据区域即可(交互流畅、减少接口压力,但部分场景数据不及时)
- 动态点击左侧tab分类, 实时网络请求对应分类下的列表数据(实现简单,效率调差,接口压力增加)
Moudel
左侧分类(班级)- 右侧子类(学生)
- ClassModel
package com.advance.yongliu.linkagedata;
import java.util.List;
/**
* author YongLiu
* date 2018/8/9.
* desc:
*/
public class ClassModel {
private int id;
private String name;
private List<StudentModel> list;
public ClassModel() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<StudentModel> getList() {
return list;
}
public void setList(List<StudentModel> list) {
this.list = list;
}
}
- StudentModel
package com.advance.yongliu.linkagedata;
/**
* author YongLiu
* date 2018/8/9.
* desc:
*/
public class StudentModel {
public String name;
public int age;
public int outId;
public StudentModel() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getOutId() {
return outId;
}
public void setOutId(int outId) {
this.outId = outId;
}
}
item布局
class_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/tv_class_name"
tools:text="班级"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
student_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center|left"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
tools:text="名字" />
<TextView
android:id="@+id/tv_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
tools:text="年龄" />
</LinearLayout>
适配器
俩侧分类列表的adapter适配器
这里我用的是BaseQuickAdapter,强烈建议你使用,很方便!扩展性也好!
- ClassAdapter
package com.advance.yongliu.linkagedata;
import android.graphics.Color;
import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;
/**
* author YongLiu
* date 2018/8/9.
* desc: 班级列表
*/
public class ClassAdapter extends BaseQuickAdapter<ClassModel, BaseViewHolder> {
private int position;
public ClassAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, ClassModel item) {
helper.setTextColor(R.id.tv_class_name, helper.getLayoutPosition() == position ? Color.parseColor("#8470FF") : Color.parseColor("#363636"));
helper.setText(R.id.tv_class_name, item.getName());
}
public void setSelection(int pos) {
this.position = pos;
notifyDataSetChanged();
}
}
- StudentAdapter
package com.advance.yongliu.linkagedata;
import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;
/**
* author YongLiu
* date 2018/8/9.
* desc: 学生列表
*/
public class StudentAdapter extends BaseQuickAdapter<StudentModel, BaseViewHolder> {
public StudentAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, StudentModel item) {
helper.setText(R.id.tv_name, item.getName()+"").setText(R.id.tv_age, item.getAge()+"");
}
}
实战使用
模拟Json数据格式
[{"id":1,"name":"一年级","list":[{"age":0,"name":"小明0","outId":1}]},{"id":2,"name":"二年级","list":[{"age":0,"name":"小红0","outId":2},{"age":1,"name":"小红1","outId":2}]}]
json结构图
一般分类内的子类都会有一个字段与分类id相关联~ 如下方的分类id与子类的outId
Effect 1 实战
MainActivity
package com.advance.yongliu.linkagedata;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private RecyclerView mRvClass;
private RecyclerView mRvStudent;
private ClassAdapter classAdapter;
private StudentAdapter studentAdapter;
private String jsonData;
private List<StudentModel> studentList;
private List<ClassModel> classAllList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simulationsData();
initView();
initData();
initAdapter();
}
private void initView() {
mRvClass = findViewById(R.id.rv_class);
mRvStudent = findViewById(R.id.rv_student);
}
private void initData() {
//解析 - 模拟数据
studentList = new ArrayList<>();
classAllList = JSON.parseArray(jsonData, ClassModel.class);
//设置 - 初始默认数据
studentList.clear();
studentList.addAll(classAllList.get(0).getList());
}
private void initAdapter() {
classAdapter = new ClassAdapter(R.layout.class_layout, classAllList);
mRvClass.setLayoutManager(new LinearLayoutManager(this));
mRvClass.setAdapter(classAdapter);
//设置默认的选取状态
classAdapter.setSelection(0);
studentAdapter = new StudentAdapter(R.layout.student_layout, studentList);
mRvStudent.setLayoutManager(new LinearLayoutManager(this));
mRvStudent.setAdapter(studentAdapter);
//左侧列表的事件处理
classAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
classAdapter.setSelection(position);
studentList.clear();
studentList.addAll(classAllList.get(position).getList());
studentAdapter.notifyDataSetChanged();
}
});
}
/**
* 数据模拟 - 可忽略 ,一般这里的数据都是后台网络请求之后返回的
*/
private void simulationsData() {
List<ClassModel> classList = new ArrayList<>();
List<StudentModel> studentList1 = new ArrayList<>();
List<StudentModel> studentList2 = new ArrayList<>();
for (int i = 0; i < 2; i++) {
StudentModel studentModel = new StudentModel();
studentModel.setName("小明" + i);
studentModel.setAge(i);
studentModel.setOutId(1);
studentList1.add(studentModel);
}
for (int i = 0; i < 3; i++) {
StudentModel studentModel = new StudentModel();
studentModel.setName("小红" + i);
studentModel.setAge(i);
studentModel.setOutId(2);
studentList2.add(studentModel);
}
ClassModel classModel = new ClassModel();
classModel.setList(studentList1);
classModel.setId(1);
classModel.setName("一年级");
ClassModel classMode2 = new ClassModel();
classMode2.setList(studentList2);
classMode2.setId(2);
classMode2.setName("二年级");
classList.add(classModel);
classList.add(classMode2);
jsonData = JSON.toJSONString(classList);
Log.e("tag", jsonData);
}
}
Effect 2 实战
MainActivity
package com.advance.yongliu.linkagedata;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private RecyclerView mRvClass;
private RecyclerView mRvStudent;
private ClassAdapter classAdapter;
private StudentAdapter studentAdapter;
private String jsonData;
private List<StudentModel> studentList;
private List<ClassModel> classAllList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simulationsData();
initView();
initData();
initAdapter();
}
private void initView() {
mRvClass = findViewById(R.id.rv_class);
mRvStudent = findViewById(R.id.rv_student);
}
private void initData() {
//解析 - 模拟数据
studentList = new ArrayList<>();
classAllList = JSON.parseArray(jsonData, ClassModel.class);
//设置 - 初始默认数据
studentList.clear();
for (int i = 0; i < classAllList.size(); i++) {
studentList.addAll(classAllList.get(i).getList());
}
}
private void initAdapter() {
classAdapter = new ClassAdapter(R.layout.class_layout, classAllList);
mRvClass.setLayoutManager(new LinearLayoutManager(this));
mRvClass.setAdapter(classAdapter);
//设置默认的选取状态
classAdapter.setSelection(0);
studentAdapter = new StudentAdapter(R.layout.student_layout, studentList);
mRvStudent.setLayoutManager(new LinearLayoutManager(this));
mRvStudent.setAdapter(studentAdapter);
/**
* 左侧列表的事件处理
* */
classAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
classAdapter.setSelection(position);
//临时变量记录当前左侧选中条目的子集数据长度
int sum = 0;
for (int i = 0; i < position; i++) {
sum += classAllList.get(i).getList().size();
}
//根据左侧,定位右侧的展示数据
LinearLayoutManager layoutManager = (LinearLayoutManager) mRvStudent.getLayoutManager();
layoutManager.scrollToPositionWithOffset(sum, 0);
}
});
/**
* 注意 - 双标联动关键
* */
mRvStudent.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//获取滚动时的第一条展示的position
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
//获取右侧数据的关联id
StudentModel studentModel = studentList.get(firstVisibleItemPosition);
int outId = studentModel.getOutId();
//记录外部id, 更新左侧状态栏状态
int pos = 0;
for (int i = 0; i < classAllList.size(); i++) {
int id = classAllList.get(i).getId();
if ((outId == id)) {
pos = i;
}
}
classAdapter.setSelection(pos);
}
});
}
/**
* 数据模拟 - 可忽略 ,一般这里的数据都是后台网络请求之后返回的
*/
private void simulationsData() {
List<ClassModel> classList = new ArrayList<>();
List<StudentModel> studentList1 = new ArrayList<>();
List<StudentModel> studentList2 = new ArrayList<>();
for (int i = 0; i < 15; i++) {
StudentModel studentModel = new StudentModel();
studentModel.setName("小明" + i);
studentModel.setAge(i);
studentModel.setOutId(1);
studentList1.add(studentModel);
}
for (int i = 0; i < 20; i++) {
StudentModel studentModel = new StudentModel();
studentModel.setName("小红" + i);
studentModel.setAge(i);
studentModel.setOutId(2);
studentList2.add(studentModel);
}
ClassModel classModel = new ClassModel();
classModel.setList(studentList1);
classModel.setId(1);
classModel.setName("一年级");
ClassModel classMode2 = new ClassModel();
classMode2.setList(studentList2);
classMode2.setId(2);
classMode2.setName("二年级");
classList.add(classModel);
classList.add(classMode2);
jsonData = JSON.toJSONString(classList);
Log.e("tag", jsonData);
}
}
- activity_main
<?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"
android:orientation="horizontal"
tools:context="com.advance.yongliu.linkagedata.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_class"
android:layout_width="90dp"
android:layout_height="match_parent"/>
<View
android:layout_width="1dp"
android:background="#363636"
android:layout_height="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_student"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_height="match_parent"/>
</LinearLayout>
Effect 3 实战
2020年补入:补入原因主要在于有位小朋友实现类似这样的效果时遇到一些问题,所以特此写了这样的一个Demo,秉承着不浪费的原则,稍加记录一波 ~
Model
- ClassifyModel
package nk.com.testademo;
import java.util.List;
/**
* @author MrLiu
* @date 2020/12/7
* desc
*/
public class ClassifyModel {
private int id;
private String name;
private List<SubclassModel> list;
public ClassifyModel() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<SubclassModel> getList() {
return list;
}
public void setList(List<SubclassModel> list) {
this.list = list;
}
}
- SubclassModel
package nk.com.testademo;
/**
* @author MrLiu
* @date 2020/12/7
* desc
*/
public class SubclassModel {
public String title;
public String des;
public String author;
public int outId;
public SubclassModel() {
super();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDes() {
return des;
}
public void setDes(String des) {
this.des = des;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getOutId() {
return outId;
}
public void setOutId(int outId) {
this.outId = outId;
}
}
列表的item布局
- item_classify.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/tv_class_name"
tools:text="班级"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
- item_subclass.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="名字"
/>
<TextView
android:id="@+id/tv_dsc"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="描述"
/>
<TextView
android:id="@+id/tv_author"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="作者"
android:textColor="#CCCCCC"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:background="#000000"
/>
</LinearLayout>
分类与子类适配器
- ClassifyAdapter
package nk.com.testademo;
import android.graphics.Color;
import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;
/**
* @author MrLiu
* @date 2020/12/7
* desc
*/
public class ClassifyAdapter extends BaseQuickAdapter<ClassifyModel, BaseViewHolder> {
private int position;
public ClassifyAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, ClassifyModel item) {
helper.setTextColor(R.id.tv_class_name, helper.getLayoutPosition() == position ? Color.parseColor("#8470FF") : Color.parseColor("#363636"));
helper.setText(R.id.tv_class_name, item.getName());
}
public void setSelection(int pos) {
this.position = pos;
notifyDataSetChanged();
}
}
- SubclassAdapter
package nk.com.testademo;
import android.support.annotation.Nullable;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;
/**
* @author MrLiu
* @date 2020/12/7
* desc
*/
public class SubclassAdapter extends BaseQuickAdapter<SubclassModel, BaseViewHolder> {
public SubclassAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, SubclassModel item) {
TextView title = helper.getView(R.id.tv_title);
title.setText(isStringNull(item.getTitle())?"":item.getTitle());
helper.setText(R.id.tv_title, item.getTitle()).setText(R.id.tv_dsc, item.getDes()).setText(R.id.tv_author, item.getAuthor());
}
/**
* 判断字符串是否为null的方法
*/
public static boolean isStringNull(String str) {
return str == null || "".equals(str) || " ".equals(str) || "[]".equals(str) || str.length() == 0;
}
}
主类调用
- MainActivity
package nk.com.testademo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private RecyclerView mRvClass;
private RecyclerView mRvStudent;
private ClassifyAdapter classAdapter;
private SubclassAdapter studentAdapter;
private String jsonData;
private List<SubclassModel> studentList;
private List<ClassifyModel> classAllList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simulationsData();
initView();
initData();
initAdapter();
}
private void initView() {
mRvClass = findViewById(R.id.rv_class);
mRvStudent = findViewById(R.id.rv_student);
}
private void initData() {
//解析 - 模拟数据
studentList = new ArrayList<>();
classAllList = JSON.parseArray(jsonData, ClassifyModel.class);
//设置 - 初始默认数据
studentList.clear();
for (int i = 0; i < classAllList.size(); i++) {
studentList.addAll(classAllList.get(i).getList());
}
}
private void initAdapter() {
classAdapter = new ClassifyAdapter(R.layout.item_classify, classAllList);
mRvClass.setLayoutManager(new LinearLayoutManager(this));
mRvClass.setAdapter(classAdapter);
//设置默认的选取状态
classAdapter.setSelection(0);
studentAdapter = new SubclassAdapter(R.layout.item_subclass, studentList);
mRvStudent.setLayoutManager(new LinearLayoutManager(this));
mRvStudent.setAdapter(studentAdapter);
/**
* 左侧列表的事件处理
* */
classAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
classAdapter.setSelection(position);
//临时变量记录当前左侧选中条目的子集数据长度
int sum = 0;
for (int i = 0; i < position; i++) {
sum += classAllList.get(i).getList().size();
}
//根据左侧,定位右侧的展示数据
LinearLayoutManager layoutManager = (LinearLayoutManager) mRvStudent.getLayoutManager();
layoutManager.scrollToPositionWithOffset(sum, 0);
}
});
/**
* 注意 - 双标联动关键
* */
mRvStudent.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//获取滚动时的第一条展示的position
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
//获取右侧数据的关联id
SubclassModel subclassModel = studentList.get(firstVisibleItemPosition);
int outId = subclassModel.getOutId();
//记录外部id, 更新左侧状态栏状态
int pos = 0;
for (int i = 0; i < classAllList.size(); i++) {
int id = classAllList.get(i).getId();
if (outId == id) {
pos = i;
}
}
classAdapter.setSelection(pos);
}
});
}
/**
* 数据模拟 - 可忽略 ,一般这里的数据都是后台网络请求之后返回的
*/
private void simulationsData() {
List<ClassifyModel> classList = new ArrayList<>();
List<SubclassModel> studentList1 = new ArrayList<>();
List<SubclassModel> studentList2 = new ArrayList<>();
List<SubclassModel> studentList3 = new ArrayList<>();
for (int i = 0; i < 8; i++) {
SubclassModel subclassModel = new SubclassModel();
subclassModel.setTitle("射雕英雄传" + i);
subclassModel.setDes("作品最初于1957到1959年在《香港商报》上连载,后收入《金庸作品集》中,连同后来的《神雕侠侣》和《倚天屠龙记》一并,被称为金庸小说的“射雕三部曲”" + i);
subclassModel.setAuthor("金庸" + i);
subclassModel.setOutId(1);
studentList1.add(subclassModel);
}
for (int i = 0; i < 10; i++) {
SubclassModel subclassModel = new SubclassModel();
subclassModel.setTitle("小李飞刀" + i);
subclassModel.setDes("明朝中期成化年间,厌倦了官场世俗的文武全才李寻欢遇难之际被武林高手龙啸云相救,二人结为义兄弟。李寻欢和林诗音从小指腹为婚,彼此相爱相杀" + i);
subclassModel.setAuthor("古龙" + i);
subclassModel.setOutId(2);
studentList2.add(subclassModel);
}
for (int i = 0; i < 9; i++) {
SubclassModel subclassModel = new SubclassModel();
subclassModel.setTitle("游剑江湖" + i);
subclassModel.setDes("杭州侠女云紫萝与孟元超真心相爱,孟元超为救师父远赴小金川,并 参加义军,后误传牺牲。已怀孕的云紫萝无奈嫁给蓟州名武师杨牧,并生 一子名杨华。" + i);
subclassModel.setAuthor("梁羽生" + i);
subclassModel.setOutId(3);
studentList3.add(subclassModel);
}
ClassifyModel classModel = new ClassifyModel();
classModel.setList(studentList1);
classModel.setId(1);
classModel.setName("月票榜");
ClassifyModel classMode2 = new ClassifyModel();
classMode2.setList(studentList2);
classMode2.setId(2);
classMode2.setName("畅销榜");
ClassifyModel classMode3 = new ClassifyModel();
classMode3.setList(studentList3);
classMode3.setId(3);
classMode3.setName("新书榜");
classList.add(classModel);
classList.add(classMode2);
classList.add(classMode3);
jsonData = JSON.toJSONString(classList);
Log.e("tag", jsonData);
}
}
- activity_main
<?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"
android:orientation="horizontal"
tools:context="com.advance.yongliu.linkagedata.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_class"
android:layout_width="90dp"
android:layout_height="match_parent"/>
<View
android:layout_width="1dp"
android:background="#363636"
android:layout_height="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_student"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_height="match_parent"/>
</LinearLayout>