There is an activity with recyclView.
public class NotesActivity extends AppCompatActivity implements adapter.ItemTouchHelper.ItemTouchHelperListener{ public List<Notes> notesList; private NotesHandler notesHandler; private NotesAdapter notesAdapter; private RecyclerView recyclerView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notes_activity); notesHandler = new NotesHandler(getApplicationContext()); recyclerView = findViewById(R.id.recycle_view); prepareData(); notesAdapter = new NotesAdapter(getApplicationContext(), notesList); RecyclerView.LayoutManager manager = new LinearLayoutManager(getApplicationContext()); recyclerView.setLayoutManager(manager); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL)); recyclerView.setAdapter(notesAdapter); In which there is a list of elements, by pressing which, I receive data from the element and open a new activity, I use it to edit the data.
@Override public void onClick(View v) { int pos = getAdapterPosition(); if (pos != RecyclerView.NO_POSITION){ Intent intent = new Intent(context, CreateActivity.class); intent.putExtra("id", pos); intent.putExtra("title", textViewTitle.getText().toString()); intent.putExtra("text", textViewText.getText().toString()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } In another activity I get this data.
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.creature_activity); notesHandler = new NotesHandler(this); editSubject = findViewById(R.id.edit_subject); editText = findViewById(R.id.edit_text); int id; String title; String text; id = getIntent().getExtras().getInt("id"); title = getIntent().getExtras().getString("title"); text = getIntent().getExtras().getString("text"); if (title != null && text != null){ editSubject.setText(title); editText.setText(text); } } But I still use this activity to create data, where I don’t need to receive it, the above described. How to be? To put
try { } catch (Exception e){ } ???
Intent i = getIntent(); if (i == null) ...создание... else .. редактирование..Intent i = getIntent(); if (i == null) ...создание... else .. редактирование..- pavlofff