Android RecyclerView update Adapter -
i've got recyclerview
adapter. tried set adapter
programmatically, doesnt work.
here's code:
public class recordadapter extends recyclerview.adapter<recordviewholder>{ private list<recorddata> records; public recordadapter(){ records = new arraylist<>(); } @override public recordviewholder oncreateviewholder(viewgroup parent, int viewtype) { flog.d("records: creating new recordviewholder"); view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.record_item, parent, false); return new recordviewholder(view); } @override public void onbindviewholder(recordviewholder holder, int position) { recorddata data = records.get(position); flog.d("records: binding new recordviewholder"); holder.mrecordtext.settext("record " + position); } @override public int getitemcount() { flog.d("records: count - " + records.size()); return records.size(); } public void addrecord(recorddata newrecord){ records.add(newrecord); this.notifydatasetchanged(); } }
my recordviewholder is:
public class recordviewholder extends recyclerview.viewholder{ @bind(r.id.record_play_button) public imagebutton mrecordplay; @bind(r.id.record_message_text) public textview mrecordtext; @bind(r.id.record_seek_bar) public seekbar mseekbar; public recordviewholder(view itemview){ super(itemview); butterknife.bind(this, itemview); }
i've tried set adapter this:
if (adapter == null){ adapter = new recordadapter(); } adapter.addrecord(recorddata); holder.mincomingrecordlist.setadapter(adapter);
but adapter
didnt call methoda oncreateviewholder
, onbindviewholder
my xml
file recyclerview
:
<linearlayout xmlns:a="http://schemas.android.com/apk/res/android" a:orientation="vertical" a:layout_width="wrap_content" a:layout_height="wrap_content"> <linearlayout a:layout_width="wrap_content" a:layout_height="wrap_content"> ....... <linearlayout a:layout_width="wrap_content" a:layout_height="wrap_content"> <android.support.v7.widget.recyclerview a:layout_width="match_parent" a:layout_height="match_parent" a:id="@+id/record_list"/> </linearlayout> </linearlayout> </linearlayout>
Comments
Post a Comment