AndroidStudio制作RecyclerView完成习题详情的展示
程序员文章站
2022-12-11 08:22:13
androidstudio制作recyclerview完成习题详情的展示。
适配器
adapter:
private list objects = new arraylist();
p...
androidstudio制作recyclerview完成习题详情的展示。
适配器
adapter:
private list objects = new arraylist(); private context context; private layoutinflater layoutinflater; public exerciseslistitemadapter(context context){ this.context=context; this.layoutinflater=layoutinflater.from(context); } /** * 设置数据更新界面 */ public void setdata(list objects){ this.objects = objects; notifydatasetchanged(); } // public void updateview(list objects){ this.objects = objects; this.notifydatasetchanged(); } @override public int getcount() { return objects == null ? 0 : objects.size(); } /** * 根据position得到对应的item的对象 */ @override public exercisesbean getitem(int position) { return objects.get(position); } /** * 根据position得到对应item的对象 */ @override public long getitemid(int position) { return position; }
布局
导入依赖库
示意图build.gradle(moudle:app)的图给大家做参考
示意图同时也可以这样:
android { compilesdkversion 26 defaultconfig { } buildtypes { release { } } buildtoolsversion '26.0.2' } dependencies { implementation filetree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testimplementation 'junit:junit:4.12' androidtestimplementation 'com.android.support.test:runner:1.0.1' androidtestimplementation 'com.android.support.test.espresso:espresso-core:3.0.1' implementation 'com.android.support:recyclerview-v7:26.1.0' }
添加跳转页面的代码
//跳转到习题界面 intent intent = new intent(context, exercisesdetailactivity.class); intent.putextra("id", bean.id); intent.putextra("title", bean.title); ((activity) context).startactivityforresult(intent, 000);