Как извлечь данные, сохраненные в деятельности, в другую деятельность, используя базу данных ORMlite

Я хочу получить данные (заметки), которые хранятся и отображаются в основной деятельности. на другое действие, чтобы заставить меня редактировать или удалить ту же заметку, на которую я нажал. здесь MainActivity.java код:

public RecyclerView recyclerNotes;
private  FloatingActionButton fabAddNote;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   fabAddNote = (FloatingActionButton) findViewById(R.id.fab_add_note);
    recyclerNotes = (RecyclerView) findViewById(R.id.recycler_notes);
    recyclerNotes.setLayoutManager(new GridLayoutManager(this,2));
    fabAddNote.setOnClickListener(this);
    recyclerNotes.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0)
               fabAddNote.hide();
            else if (dy < 0)
                fabAddNote.show();
        }
    });

    getAllNotes();

}

@Override
protected void onResume() { 
    super.onResume();
    getAllNotes();
}

private void getAllNotes() {
    //// TODO: get all notes from SQLite database
    DatabaseHelper helper = new DatabaseHelper(this);

    try {
        List<Note> notes = helper.getNoteDao().queryForAll();
        NotesAdaptor adaptor = new NotesAdaptor(notes);
        recyclerNotes.setAdapter(adaptor);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}


@Override
public void onClick(View view) {
    //todo : Open AddNewNote Activity
    Intent i = new Intent(this, AddNoteActivity.class);
    startActivity(i);
}

}

а вот действия адаптера вьюблера, которые отображают вид заметки:

public class NotesAdaptor extends RecyclerView.Adapter<NotesAdaptor.NoteViewHolder> {

List<Note> notes;

public NotesAdaptor(List<Note> notes) {
    this.notes = notes;

}

@Override
public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new NoteViewHolder(LayoutInflater.from(parent.getContext())
            .inflate(R.layout.item_note,parent,false));
}

@Override
public void onBindViewHolder(NoteViewHolder holder, int position) {
    holder.note = notes.get(position);
    holder.tvNoteTitle.setText(holder.note.getTitle());
    holder.tvNoteDescription.setText(holder.note.getDescription());


}

@Override
public int getItemCount() {
    return notes.size();
}

class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    View noteView;
    TextView tvNoteTitle, tvNoteDescription;
    Note note;

    public NoteViewHolder(View itemView) {
        super(itemView);
        noteView = itemView;
        tvNoteTitle = noteView.findViewById(R.id.tv_note_title);
        tvNoteDescription = noteView.findViewById(R.id.tv_note_desc);
        itemView.setOnClickListener(this);

    }


    @Override
    public void onClick(View view) {

       Intent i = new Intent(noteView.getContext(), DeleteOrEditNoteActivity.class);
       noteView.getContext().startActivity(i);
        }
    }
    }

Я хочу поделиться данными (заголовком и описанием) выбранной заметки при открытии DeleteOrEditActivity.java

0 ответов

Другие вопросы по тегам