0

I've got a recyclerView with adapter. I tried to set adapter programmatically, but it doesnt work.

Here's my 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 is - " + 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 to set adapter like this:

if (adapter == null){
    adapter = new RecordAdapter();
}

adapter.addRecord(recordData);
holder.mIncomingRecordList.setAdapter(adapter);

But I my adapter didnt call methoda onCreateViewHolder and onBindViewHolder

My XML file with 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>
hrskrs
  • 4,447
  • 5
  • 38
  • 52
Vanya Sakharovskiy
  • 295
  • 1
  • 3
  • 16

0 Answers0