RecyclerView with in recyclerView with start ActivityOnresult

前端 未结 1 1792
后悔当初
后悔当初 2021-01-24 01:31

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

相关标签:
1条回答
  • 2021-01-24 02:02

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

    0 讨论(0)
提交回复
热议问题