A
A
Alexey2017-09-21 12:40:37
Android
Alexey, 2017-09-21 12:40:37

What is the error in displaying the RecyclerView widget?

The code that should display the RecyclerView with data:

The code
public class NotesListFragment extends Fragment {
    
    public NotesListFragment() {
      
    }
    
    private RecyclerView mNoteRecyclerView;
    private NoteAdapter mNoteAdapter;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      NotesBase note  = NotesBase.get(getActivity());
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.notes_list_fragment, container, false);
      mNoteRecyclerView = (RecyclerView) view.findViewById(R.id.note_recycler_view);
      mNoteRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      
      updateUI();
      
      return view;
    }
    
    
    private class NoteHolder extends RecyclerView.ViewHolder {
      private TextView mTitleNoteTextView;
      private TextView mDateNoteTextView;
      
      public NoteHolder(View itemView) {
        super(itemView);
        
        mTitleNoteTextView = (TextView) itemView.findViewById(R.id.ItemNoteTitle);
        mDateNoteTextView = (TextView) itemView.findViewById(R.id.ItemNoteDate);
      }
      
      public void bindNote (Note note) {
        Note mNote = note;
        
        mTitleNoteTextView.setText(mNote.getmTitle_n());
        mDateNoteTextView.setText(mNote.getmDate_n().toString());
      }
    
    }
        
    
    private class NoteAdapter extends RecyclerView.Adapter<NoteHolder> {
      private List<Note> mNotes;
      
      public NoteAdapter(List<Note> notes) {
        mNotes = notes;
      }
      
      
      public NoteHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
        View view = layoutInflater.inflate(R.layout.list_item, parent, false);
        return new NoteHolder(view);
      }
      
      
      public void onBindViewHolder(NoteHolder holder, int position) {
        Note note = mNotes.get(position);
        holder.bindNote(note);
      }
      
      
      public int getItemCount() {
        return mNotes.size();
      }
    }
    
    
    private void updateUI() {
      NotesBase notesBase = NotesBase.get(getActivity());
      List<Note> notes = notesBase.getNotes();
      
      mNoteAdapter = new NoteAdapter(notes);
      mNoteRecyclerView.setAdapter(mNoteAdapter);
    }
    
  }


Widget markup:
markup
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    
    <android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/note_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>


In the visual editor "the following classes could not be instantiated android.support.v7.widget.recyclerview"
Application crashes, logs:
Logs
214a3c2f258841a78fd2e81e008f9336.png293fd39292dd428b9617b7b916ffe212.pngc89dccf6e31f4326af43f43731790889.png

Application under android 4.2.2 (api 17), widget library file 21.0.2, IDE Eclipse Mars 2
How to correct the situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2017-09-21
@aol-nnov

install android support library via sdk manager

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question