I have a recycler view(A) containing another recyclerview(B). When I click on the plus icon in recyclerview(A) item, it opens up a new activity with a recyclerview(C). Long pres
First change your code by this below :
holder.eventUpcomingAddPeople.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Activity origin = (Activity) context;
Intent i = new Intent(getAppContext(), ContactsActivity.class);
i.putExtra("selectedPosition", position);
origin.startActivityForResult(i, CONTACT_CODE);
}
});
@Override
public void onReceived(int requestCode, int resultCode, Intent data) {
if (requestCode == CONTACT_CODE && resultCode == RESULT_OK && data != null) {
int result = data.getIntExtra("selectedPosition","put a default value in case of null");
List<Contact> contactsLists = (ArrayList<Contact>) data.getSerializableExtra("contacts");
contactsList.clear();
contactsList.addAll(contactsLists);
contactAdapter.setContactList(contactsLists);
upcomingEventsAdapter.notifyItemChanged(result);
}
}
on the second activity you should have something like that when you click on done :
int param = getIntent().getIntExtra("selectedPosition");
Intent resultIntent = new Intent();
resultIntent.putExtra("contacts", Your selected contacts);
resultIntent.putExtra("selectedPosition", param);
setResult(RESULT_OK, resultIntent);
finish();
Hope it's clear and helpful :)