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);
}
}