RecyclerView with in recyclerView with start ActivityOnresult

て烟熏妆下的殇ゞ 提交于 2019-12-02 04:23:39

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!