android - Adding a footer view in RECYCLER VIEW? -
i want add footer layout @ base of recycler view.below adapter view inflates header layout other items well.help appreciated!
public class splitmembersadapter extends recyclerviewadapter<splitmember, splitmemberviewholder> { private final arraylist<splitmember> msplitmemberslist; private final imageloader mimageloader; private static final int type_header = 0; private static final int type_item = 1; private int splitamount; private boolean isamountsplitted; public splitmembersadapter(arraylist<splitmember> members,imageloader imageloader) { msplitmemberslist = members; mimageloader = imageloader; } @override public int getitemcount() { return msplitmemberslist.size(); } @override public int getitemviewtype(int position) { if (ispositionheader(position)) { return type_header; } return type_item; } private static boolean ispositionheader(int position) { return position == 0; } @override public splitmemberviewholder oncreateviewholder(viewgroup viewgroup, int viewtype) { view itemview = layoutinflater.from(viewgroup.getcontext()). inflate(r.layout.split_member_item_layout, viewgroup, false); return new splitmemberviewholder(itemview); } @override public void onbindviewholder(splitmemberviewholder viewholder, int position) { splitmember contact = msplitmemberslist.get(position); viewholder.splitmemamount.settext(string.format("%.2f", contact.getshare())); viewholder.splitmembercolor.setbackgroundcolor(contact.getcolor()); if (position == type_header){ viewholder.splitmemname.settext("you"); mimageloader.loadimage(contact.getimg(), viewholder.splitmemimg, r.drawable.empty_user_placeholder); } else { viewholder.splitmemname.settext(contact.getname()); mimageloader.loadimage(utils.getprofileimageurl(contact.getimg()), viewholder.splitmemimg,r.drawable.empty_user_placeholder); } } } class splitmemberviewholder extends recyclerview.viewholder { public bezelimageview splitmemimg; public textview splitmemname; public textview splitmemamount; public view splitmembercolor; public splitmemberviewholder(view itemview) { super(itemview); splitmembercolor = itemview.findviewbyid(r.id.member_color); splitmemimg = (bezelimageview) itemview.findviewbyid(r.id.member_profile_image); splitmemname = (textview) itemview.findviewbyid(r.id.member_name); splitmemamount = (textview) itemview.findviewbyid(r.id.member_amount); } }
similar to adding header add footer too.
public class splitmembersadapter extends recyclerviewadapter<splitmember, splitmemberviewholder> { private final arraylist<splitmember> msplitmemberslist; private final imageloader mimageloader; private static final int type_header = 0; private static final int type_item = 1; private static final int type_footer = 2; private int splitamount; private boolean isamountsplitted; public splitmembersadapter(arraylist<splitmember> members,imageloader imageloader) { msplitmemberslist = members; mimageloader = imageloader; } @override public int getitemcount() { return msplitmemberslist.size(); } @override public int getitemviewtype(int position) { if (ispositionheader(position)) { return type_header; }else if (ispositionfooter(position)) { return type_footer; } return type_item; } private static boolean ispositionheader(int position) { return position == 0; } private static boolean ispositionfooter(int position) { return position == msplitmemberslist.size()-1; } @override public splitmemberviewholder oncreateviewholder(viewgroup viewgroup, int viewtype) { switch(viewtype){ case type_header: //return header view holder; break; case type_item: //return item view holder; break; case type_footer: //return footer view holder; break; } } @override public void onbindviewholder(splitmemberviewholder viewholder, int position) { switch(getitemviewtype(position)){ case type_header: //bind header data; break; case type_item: //bind item data break; case type_footer: //bind footer data. break; } } } class splitmemberviewholder extends recyclerview.viewholder { public bezelimageview splitmemimg; public textview splitmemname; public textview splitmemamount; public view splitmembercolor; public splitmemberviewholder(view itemview) { super(itemview); splitmembercolor = itemview.findviewbyid(r.id.member_color); splitmemimg = (bezelimageview) itemview.findviewbyid(r.id.member_profile_image); splitmemname = (textview) itemview.findviewbyid(r.id.member_name); splitmemamount = (textview) itemview.findviewbyid(r.id.member_amount); } }
Comments
Post a Comment