使用时一定要在builde.gradle文件里添加依赖:compile 'com.android.support:recyclerview-v7:22.0.+'
======================================================
public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private Button fanxuan; private Button quanxuan; private LinearLayoutManager layoutManager; private myAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recycleview); quanxuan = (Button) findViewById(R.id.allcheck); fanxuan = (Button) findViewById(R.id.fanxuan); //在加载数据之前配置 layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); //适配器 adapter = new myAdapter(); recyclerView.setAdapter(adapter); quanxuan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { adapter.all(); } }); fanxuan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { adapter.Fanxuan(); } }); }}
====================================================================
public class myViewHolder extends RecyclerView.ViewHolder { public View view; public TextView textView;
使用RecyclerView展示checkBox全选反选
最新推荐文章于 2024-04-13 19:27:29 发布
该博客展示了如何在Android应用中使用RecyclerView配合checkBox,实现在列表中进行全选和反选的功能。通过创建自定义Adapter和ViewHolder,以及设置点击事件来控制每个checkBox的状态,并更新视图。
摘要由CSDN通过智能技术生成