java - Interface value is always null -
i using custom recycler view , in adapter class have implemented interface null on button click. here adapter class.
public class feedlistadapter extends recyclerview.adapter<addtocartholder> { private onfeeditemclicklistener onfeeditemclicklistener; public feedlistadapter(activity activity, arraylist<cartitem> feeditems) { this.activity = activity; this.feeditems = feeditems; this.filteredfeeditems = feeditems; inflater = layoutinflater.from(activity); } public void setonfeeditemclicklistener(onfeeditemclicklistener onfeeditemclicklistener) { this.onfeeditemclicklistener = onfeeditemclicklistener; } @override public addtocartholder oncreateviewholder(viewgroup parent, int viewtype) { view v = layoutinflater.from(parent.getcontext()).inflate( r.layout.feed_item, parent, false); addtocartholder viewholder = new addtocartholder(v); setupclickableviews(v, viewholder); return viewholder; } @override public void onbindviewholder(final addtocartholder holder, int position) { cartitem item = (cartitem) filteredfeeditems.get(position); holder.price.settext((string.valueof(item.getproductname()) + "")); holder.location.settext((string.valueof(item.getquantity())) + ""); } private void setupclickableviews(final view view, final addtocartholder cellfeedviewholder) { cellfeedviewholder.plus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if(onfeeditemclicklistener !=null){ onfeeditemclicklistener.onaddclick(v, cellfeedviewholder.getadapterposition()); } else{ toast.maketext(activity, "data null", toast.length_long).show(); } } }); } public interface onfeeditemclicklistener { void onaddclick(view v, int position); } @override public int getitemcount() { return filteredfeeditems.size(); }
i getting null whenever clicking on button down know why coming null...
here fragment class have implemented interface.
public class myfragment extends fragment implements feedlistadapter.onfeeditemclicklistener{ // method @override public void onaddclick(view v, int position) { // todo auto-generated method stub snackbar.make(clcontent, "product removed cart!", snackbar.length_short).show(); }
you must instantiating feedlistadapter in fragment correct buddy ???
like using statement :
feedlistadapter adapter = new feedlistadapter(this.getactivity(),your_array_list)
after instantiating adapter call adapter's setonfeeditemclicklistener 'this'
argument :) that's :)
adapter.setonfeeditemclicklistener(this)
hope answer helped :) happy coding buddy :)
Comments
Post a Comment