开篇
有一个需求,需要做一个左右双向联动的列表。类似于饿了么点餐页面,但是远没有那么复杂,只是用于展示的一个页面。只用了两个RecycleView加适配器,没有调用Fragment。
![](https://i-blog.csdnimg.cn/blog_migrate/630941e1158c37b1786ab458c6696d28.png)
MainActivity
public class MainActivity extends Activity {
private RecyclerView mRvClass;
private RecyclerView mRvStudent;
private ClassAdapter classAdapter;
private StudentAdapter studentAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initAdapter();
}
private void initView() {
mRvClass = findViewById(R.id.rv_class);
mRvStudent = findViewById(R.id.rv_student);
}
private void initAdapter() {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
mRvClass.setLayoutManager(linearLayoutManager);
classAdapter = new ClassAdapter(MainActivity.this);
mRvClass.setAdapter(classAdapter);
//设置默认的选取状态
mRvClass.setScrollingTouchSlop(0);
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(MainActivity.this);
mRvStudent.setLayoutManager(linearLayoutManager1);