@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_edit_note, container, false);

    titleEditText = (EditText) rootView.findViewById(R.id.titleEditText);
    contentEditText = (EditText) rootView.findViewById(R.id.contentEditText);

    if (getArguments() != null) {
      note =
          new Note(
              getArguments().getString(ARG_ID),
              getArguments().getString(ARG_TITLE),
              getArguments().getString(ARG_CONTENT));

      titleEditText.setText(note.getTitle());
      // Place cursor at the end of title
      titleEditText.setSelection(titleEditText.getText().length());
      contentEditText.setText(note.getContent());

      showKeyboard = getArguments().getBoolean(ARG_SHOW_KEYBOARD);
    }

    titleEditText.clearFocus();

    if (showKeyboard) {
      titleEditText.requestFocus();
    }

    getActivity().setTitle(getString(R.string.title_add_note));
    return rootView;
  }
Beispiel #2
0
 public void updateNote(Note newNote, Note oldNote) {
   for (Note note : notes) {
     if (oldNote.getId().equals(note.getId())) {
       note.setTitle(newNote.getTitle());
       note.setContent(newNote.getContent());
       notes.remove(note);
       notes.add(0, note);
       notesRecyclerView.scrollToPosition(0);
       notesAdapter.notifyDataSetChanged();
       break;
     }
   }
 }