private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
public void bindTo(Note note) { this.note = note; text.setText(note.getText()); comment.setText(note.getComment()); }
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(0, noteText, comment, new Date()); noteDao.insert(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); updateNotes(); }
@Test public void testParentAndChildren() { Box<Note> box = store.boxFor(Note.class); Note parent = new Note(); parent.setText("Parent"); Note note = new Note(); note.setText("Child"); note.setParent(parent); long childId = box.put(note); long parentId = note.getParent().getId(); assertTrue(parentId > 0); Note noteFromBox = box.get(childId); assertEquals("Child", noteFromBox.getText()); assertEquals("Parent", noteFromBox.getParent().getText()); Note parentNoteFromBox = box.get(parentId); assertEquals(1, parentNoteFromBox.getChildren().size()); assertEquals(childId, parentNoteFromBox.getChildren().get(0).getId()); } }
@Override public void onNoteClick(@Nullable Note note) { if (note == null) { return; } notesBox.remove(note); Log.d(App.TAG, "Deleted note, ID: " + note.getId()); } };
public static void main(String[] args) { BoxStore store = MyObjectBox.builder().name("objectbox-notes-db").build(); Box<Note> box = store.boxFor(Note.class); String text = args.length > 0 ? String.join(" ", args) : "No text given"; box.put(new Note(text)); System.out.println(box.count() + " notes in ObjectBox database:"); for (Note note : box.getAll()) { System.out.println(note); } store.close(); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = notesAdapter.getItem(position); Long noteId = note.getId(); noteDao.deleteByKey(noteId); Log.d(App.TAG, "Deleted note, ID: " + noteId); updateNotes(); } };
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
@Override public View getView(int position, View convertView, ViewGroup parent) { NoteViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_note, parent, false); holder = new NoteViewHolder(convertView); convertView.setTag(holder); } else { holder = (NoteViewHolder) convertView.getTag(); } Note note = getItem(position); holder.text.setText(note.getText()); holder.comment.setText(note.getComment()); return convertView; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = notesAdapter.getItem(position); notesBox.remove(note); Log.d(App.TAG, "Deleted note, ID: " + note.getId()); updateNotes(); } };
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
@Override public View getView(int position, View convertView, ViewGroup parent) { NoteViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_note, parent, false); holder = new NoteViewHolder(convertView); convertView.setTag(holder); } else { holder = (NoteViewHolder) convertView.getTag(); } Note note = getItem(position); holder.text.setText(note.getText()); holder.comment.setText(note.getComment()); return convertView; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = notesAdapter.getItem(position); notesBox.remove(note); Log.d(App.TAG, "Deleted note, ID: " + note.getId()); } };
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); updateNotes(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { NoteViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_note, parent, false); holder = new NoteViewHolder(convertView); convertView.setTag(holder); } else { holder = (NoteViewHolder) convertView.getTag(); } Note note = getItem(position); holder.text.setText(note.getText()); holder.comment.setText(note.getComment()); return convertView; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = notesAdapter.getItem(position); notesBox.remove(note); Log.d(App.TAG, "Deleted note, ID: " + note.getId()); } };