android - RecyclerView displaying every view on a different page after moving to api23 -
i have moved api 22 23 today , recycler view presents undesired behaviour.it puts every row item - view on separate page. i'm sorry putting multiple classes in 1 place not submit question otherwise due 'unformatted' code please see below:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/grey"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_marginbottom="1dp" android:padding="10dp" android:background="@drawable/ripple" > <imageview android:id="@+id/listicon" android:layout_width="80dp" android:layout_height="80dp" android:layout_marginright="8dp" android:src="@drawable/ic_launcher" /> <textview android:id="@+id/listtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/listicon" android:textsize="16sp" android:textstyle="bold" android:text="lorum ipsum" android:textcolor="@color/black" /> <textview android:id="@+id/listtext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/listicon" android:textsize="12sp" android:layout_below="@id/listtitle" android:text="lorum ipsum" /> </relativelayout> </relativelayout> <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:theme="@style/theme.appcompat.light.darkactionbar"> <linearlayout android:id="@+id/containerl" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> </linearlayout> <android.support.v7.widget.recyclerview android:id="@+id/trainingview" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.recyclerview> <android.support.design.widget.floatingactionbutton android:id="@+id/add_wrkt_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentend="true" android:layout_alignparentright="true" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:elevation="@dimen/fab_elevation" android:onclick="showaddlistdialog" android:src="@drawable/icon_add"/> </relativelayout> public class workoutpickeradapter extends firebaserecyclerviewadapter<rowinfo, workoutpickeradapter.myviewholder> { private static clicklistener clicklistener; public workoutpickeradapter(class<rowinfo> modelclass, int modellayout, class<myviewholder> viewholderclass, query ref) { super(modelclass, modellayout, viewholderclass, ref); } public void setclicklistener(clicklistener clicklistener) { this.clicklistener = clicklistener; } public static class myviewholder extends recyclerview.viewholder implements view.onclicklistener { textview title; textview text; imageview icon; public myviewholder(view itemview) { super(itemview); title = (textview) itemview.findviewbyid(r.id.listtitle); icon = (imageview) itemview.findviewbyid(r.id.listicon); text = (textview) itemview.findviewbyid(r.id.listtext); itemview.setonclicklistener(this); } @override public void onclick(view view) { if (clicklistener != null) { clicklistener.itemclicked(view, getposition()); } } } int icons[] = {r.drawable.ex_bench_press, r.drawable.ex_incline_press, r.drawable.ex_dumbbell_flyes, r.drawable.ex_dips, r.drawable.ex_triceps_extension, r.drawable.ex_deadlift, r.drawable.ex_pull_up, r.drawable.ex_dumbbell_rows, r.drawable.ex_shrugs, r.drawable.ex_ezbar_curl, r.drawable.ex_hammer_curl, r.drawable.ex_squat, r.drawable.ex_legpress, r.drawable.ex_legcurls, r.drawable.ex_calvesraise, r.drawable.ex_military_press, r.drawable.ex_lateralraise, r.drawable.ex_barbell_rows, r.drawable.ez_barbell_curl, r.drawable.ic_launcher }; @override protected void populateviewholder(myviewholder viewholder, rowinfo model, int position) { viewholder.title.settext(model.gettitle()); viewholder.text.settext(model.gettext()); string typeclean = model.gettypeclean(); public class workoutpicker extends fragment implements workoutpickeradapter.clicklistener { private recyclerview recyclerview; private floatingactionbutton fab; private workoutpickeradapter adapter; private string encodedemail; public workoutpicker() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.activity_workout_picker, container, false); encodedemail = preferencemanager.getdefaultsharedpreferences(getactivity()). getstring("email", null); firebase workoutrecords = new firebase("https://personalgymlog.firebaseio.com/workout").child(encodedemail); adapter = new workoutpickeradapter(rowinfo.class, r.layout.rv_row, workoutpickeradapter.myviewholder.class, workoutrecords); adapter.setclicklistener(this); linearlayoutmanager mlayoutmanager; mlayoutmanager = new linearlayoutmanager(getactivity()); mlayoutmanager.setreverselayout(true); mlayoutmanager.setstackfromend(true); recyclerview = (recyclerview) v.findviewbyid(r.id.trainingview); recyclerview.setlayoutmanager(mlayoutmanager); recyclerview.setadapter(adapter); setupitemtouchhelper(); fab = (floatingactionbutton) v.findviewbyid(r.id.add_wrkt_fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { showaddlistdialog(); } }); return v; } private void setupitemtouchhelper() { itemtouchhelper.simplecallback simpleitemtouchcallback = new itemtouchhelper.simplecallback(0, itemtouchhelper.left) { @override public boolean onmove(recyclerview recyclerview, recyclerview.viewholder viewholder, recyclerview.viewholder target) { return false; } @override public void onswiped(recyclerview.viewholder viewholder, int swipedir) { int position = viewholder.getadapterposition(); string listid = adapter.getref(position).getkey(); firebase listtoremoveref = new firebase("https://personalgymlog.firebaseio.com/workout").child(encodedemail).child(listid); firebase listtoremoveref2 = new firebase("https://personalgymlog.firebaseio.com/exercises").child(encodedemail).child(listid); listtoremoveref.removevalue(); listtoremoveref2.removevalue(); } @override public int getswipedirs(recyclerview recyclerview, recyclerview.viewholder viewholder) { if (viewholder.getadapterposition() == 0) return 0; return super.getswipedirs(recyclerview, viewholder); } }; itemtouchhelper itemtouchhelper = new itemtouchhelper(simpleitemtouchcallback); itemtouchhelper.attachtorecyclerview(recyclerview); } @override public void onresume() { super.onresume(); adapter.setclicklistener(this); }
fixed height of parent(main) layout
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="100dp" android:background="@color/grey"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginbottom="1dp" android:padding="10dp" android:background="@drawable/ripple" > <imageview android:id="@+id/listicon" android:layout_width="80dp" android:layout_height="80dp" android:layout_marginright="8dp" android:src="@drawable/ic_launcher" /> <textview android:id="@+id/listtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/listicon" android:textsize="16sp" android:textstyle="bold" android:text="lorum ipsum" android:textcolor="@color/black" /> <textview android:id="@+id/listtext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/listicon" android:textsize="12sp" android:layout_below="@id/listtitle" android:text="lorum ipsum" /> </relativelayout> </relativelayout> <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:theme="@style/theme.appcompat.light.darkactionbar"> <linearlayout android:id="@+id/containerl" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> </linearlayout> <android.support.v7.widget.recyclerview android:id="@+id/trainingview" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.recyclerview> <android.support.design.widget.floatingactionbutton android:id="@+id/add_wrkt_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentend="true" android:layout_alignparentright="true" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:elevation="@dimen/fab_elevation" android:onclick="showaddlistdialog" android:src="@drawable/icon_add"/> </relativelayout> public class workoutpickeradapter extends firebaserecyclerviewadapter<rowinfo, workoutpickeradapter.myviewholder> { private static clicklistener clicklistener; public workoutpickeradapter(class<rowinfo> modelclass, int modellayout, class<myviewholder> viewholderclass, query ref) { super(modelclass, modellayout, viewholderclass, ref); } public void setclicklistener(clicklistener clicklistener) { this.clicklistener = clicklistener; } public static class myviewholder extends recyclerview.viewholder implements view.onclicklistener { textview title; textview text; imageview icon; public myviewholder(view itemview) { super(itemview); title = (textview) itemview.findviewbyid(r.id.listtitle); icon = (imageview) itemview.findviewbyid(r.id.listicon); text = (textview) itemview.findviewbyid(r.id.listtext); itemview.setonclicklistener(this); } @override public void onclick(view view) { if (clicklistener != null) { clicklistener.itemclicked(view, getposition()); } } } int icons[] = {r.drawable.ex_bench_press, r.drawable.ex_incline_press, r.drawable.ex_dumbbell_flyes, r.drawable.ex_dips, r.drawable.ex_triceps_extension, r.drawable.ex_deadlift, r.drawable.ex_pull_up, r.drawable.ex_dumbbell_rows, r.drawable.ex_shrugs, r.drawable.ex_ezbar_curl, r.drawable.ex_hammer_curl, r.drawable.ex_squat, r.drawable.ex_legpress, r.drawable.ex_legcurls, r.drawable.ex_calvesraise, r.drawable.ex_military_press, r.drawable.ex_lateralraise, r.drawable.ex_barbell_rows, r.drawable.ez_barbell_curl, r.drawable.ic_launcher }; @override protected void populateviewholder(myviewholder viewholder, rowinfo model, int position) { viewholder.title.settext(model.gettitle()); viewholder.text.settext(model.gettext()); string typeclean = model.gettypeclean(); public class workoutpicker extends fragment implements workoutpickeradapter.clicklistener { private recyclerview recyclerview; private floatingactionbutton fab; private workoutpickeradapter adapter; private string encodedemail; public workoutpicker() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.activity_workout_picker, container, false); encodedemail = preferencemanager.getdefaultsharedpreferences(getactivity()). getstring("email", null); firebase workoutrecords = new firebase("https://personalgymlog.firebaseio.com/workout").child(encodedemail); adapter = new workoutpickeradapter(rowinfo.class, r.layout.rv_row, workoutpickeradapter.myviewholder.class, workoutrecords); adapter.setclicklistener(this); linearlayoutmanager mlayoutmanager; mlayoutmanager = new linearlayoutmanager(getactivity()); mlayoutmanager.setreverselayout(true); mlayoutmanager.setstackfromend(true); recyclerview = (recyclerview) v.findviewbyid(r.id.trainingview); recyclerview.setlayoutmanager(mlayoutmanager); recyclerview.setadapter(adapter); setupitemtouchhelper(); fab = (floatingactionbutton) v.findviewbyid(r.id.add_wrkt_fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { showaddlistdialog(); } }); return v; } private void setupitemtouchhelper() { itemtouchhelper.simplecallback simpleitemtouchcallback = new itemtouchhelper.simplecallback(0, itemtouchhelper.left) { @override public boolean onmove(recyclerview recyclerview, recyclerview.viewholder viewholder, recyclerview.viewholder target) { return false; } @override public void onswiped(recyclerview.viewholder viewholder, int swipedir) { int position = viewholder.getadapterposition(); string listid = adapter.getref(position).getkey(); firebase listtoremoveref = new firebase("https://personalgymlog.firebaseio.com/workout").child(encodedemail).child(listid); firebase listtoremoveref2 = new firebase("https://personalgymlog.firebaseio.com/exercises").child(encodedemail).child(listid); listtoremoveref.removevalue(); listtoremoveref2.removevalue(); } @override public int getswipedirs(recyclerview recyclerview, recyclerview.viewholder viewholder) { if (viewholder.getadapterposition() == 0) return 0; return super.getswipedirs(recyclerview, viewholder); } }; itemtouchhelper itemtouchhelper = new itemtouchhelper(simpleitemtouchcallback); itemtouchhelper.attachtorecyclerview(recyclerview); } @override public void onresume() { super.onresume(); adapter.setclicklistener(this); }
Comments
Post a Comment