Back to project page SimpleNotes.
The source code is released under:
Apache License
If you think the Android project SimpleNotes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.moysa.simplenotes.ui.fragments; /*from ww w. j a va2 s .c o m*/ import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import com.moysa.simplenotes.R; import com.moysa.simplenotes.core.Note; import com.moysa.simplenotes.ui.activities.MainActivity; import com.moysa.simplenotes.ui.application.NoteApplication; /** * Note fragment, containing two textviews for header and message. */ public class NoteFragment extends Fragment { private static final String ARG_TITLE = "title"; private static NoteFragment instance; private Note mNote; private EditText mHeader; private EditText mMessage; private View rootView; /** * Returns a new instance of this fragment. */ public static NoteFragment newInstance() { instance = new NoteFragment(); Bundle args = new Bundle(); instance.setArguments(args); return instance; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_note, container, false); mHeader = (EditText) rootView.findViewById(R.id.header); mMessage = (EditText) rootView.findViewById(R.id.message); mHeader.setText(mNote.getName()); mMessage.setText(mNote.getMessage()); View.OnFocusChangeListener listener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { saveNote(); notifyDrawerListChanged(); } }; mHeader.setOnFocusChangeListener(listener); mMessage.setOnFocusChangeListener(listener); return rootView; } public void scipEdits() { mHeader.clearFocus(); mMessage.clearFocus(); } @Override public void onAttach(Activity activity) { super.onAttach(activity); // ((MainActivity) activity).onSectionAttached( // getArguments().getString(ARG_TITLE)); ((MainActivity) activity).onSectionAttached(this.mNote.getName()); } @Override public void onDetach() { super.onDetach(); notifyDrawerListChanged(); } private void notifyDrawerListChanged() { ((MainActivity) getActivity()).getNavigationDrawerFragment() .getArrayAdapter().notifyDataSetChanged(); } public void saveNote() { mNote.setName(mHeader.getText().toString()); mNote.setMessage(mMessage.getText().toString()); NoteApplication.getInstance().getDataBaseHelper().updateNote(mNote); } public Note getNote() { return mNote; } public static NoteFragment getInstance() { return instance; } public void setNote(Note note) { this.mNote = note; } }