android - How to delete object from onclick in recyclerview? -
i trying create first android application , im having trouble recognising easiest way delete objects shown in list.
more specifically:
i have recyclerview
of objects , wants able delete objects through onclicklistener
in list. thinking easiest way make onclicklistener
recognize index on recyclerview clicked , objectlist.remove(index), not quite sure if possible?
another way onclicklistener
recognize name of object represents @ textview
, iterate through objectlist, doesn't seem quite efficient first.
how can make onclicklistener
recognise lis titem belongs to? or there way haven't been able see?
thanks in advance!
you need implement onclicklistener inside oncreateview() method of recycler view adapter.
view v = layoutinflater.from(parent.getcontext()) .inflate(r.layout.holder_layout, parent, false); final customviewholder holder = new customviewholder(v); holder.itemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { int adapterpos = holder.getadapterposition(); if (adapterpos != recyclerview.no_position) { // can use adapterpos item in list } } });
this video explain better: https://youtu.be/imsr8nriams?t=35m46s
Comments
Post a Comment