垂直回收器内的水平回收器视图使用onactivityResult查看片段内

时间:2017-07-10 10:33:08

标签: android android-recyclerview recycler-adapter

我有一个“片段”,其中有一个垂直RecyclerView,在RecyclerView的每个项目中都有一个带有添加按钮的水平RecyclerView。单击“添加”按钮时,将调用startActivityOnResultonActivityResult上的值必须更新我点击添加按钮的特定视图中的水平RecyclerView

我几乎已经取得了所有成就,但正在发生的事情是当我更新水平RecyclerView时,水平RecyclerView的所有垂直视图项目都会更新。

在片段中

private void displayUpcomingEvents(View view) {
    upcomingEventsArrayList = new ArrayList<>();
    upcomingEvents = new UpcomingEvents("Meet and greet", "Coffee Connect | ", "Phython", "21 - ", "Jun   ", "22", "  Jun", "21 Jun 10 AM", "Washinton");
    upcomingEventsArrayList.add(upcomingEvents);
    upcomingEvents = new UpcomingEvents("Meet and greet", "Coffee Connect | ", "Phython", "21 - ", "Jun   ", "22", "  Jun", "21 Jun 10 AM", "Washinton");
    upcomingEventsArrayList.add(upcomingEvents);
    upcomingEvents = new UpcomingEvents("Meet and greet", "Coffee Connect | ", "Phython", "21 - ", "Jun   ", "22", "  Jun", "21 Jun 10 AM", "Washinton");
    upcomingEventsArrayList.add(upcomingEvents);
    upcomingEventsAdapter = new RecyclerAdapterUpcomingEvents(getContext(), upcomingEventsArrayList);

    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_upcoming_event);

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getAppContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(upcomingEventsAdapter);

}

在适配器obBindViewHolder中

  @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        UpcomingEvents upcomingEvents = upcomingEventsList.get(position);

        holder.eventUpcomingName.setText(upcomingEvents.getEventUpcomingName());
        holder.eventUpcomingType.setText(upcomingEvents.getEventUpcomingType());

        holder.eventUpcomingDate.setText(dateStartUpcomeEvent + " - " + dateEndUpcomeEvent);
        holder.eventUpcomingMonth.setText(monthStartUpcomeEvent + "    " + monthEndUpcomeEvent);

        holder.eventUpcomingAlarmNotify.setText(dateTimeUpcomeEvent +" to " +dateTimeEndUpcomeEvent);
        holder.eventUpcomingPlace.setText(upcomingEvents.getEventUpcomingPlace());

        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);
                Log.e("tag", "position==> " + position);
                origin.startActivityForResult(i, CONTACT_CODE);
            }
        });

        holder.contactRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        contactAdapter = new ContactAdapter(getAppContext(), R.layout.card__contact_image, contactsList);
        holder.contactRecyclerView.setAdapter(contactAdapter);

    }

在片段中,我应该如何收到这些数据

This is what i want

OnActivity结果

        int result = data.getIntExtra("selectedPosition", -1);
        contactsLists = (ArrayList<Contact>) data.getSerializableExtra("contacts");
        for (int i = 0; i < contactsLists.size(); i++) {
            Contact contact = contactsLists.get(i);

            if (!otherUserKey.contains(contact.getId())) {
                otherUserKey.add(contact.getId());
                contactsList.add(contact);
            } else {
                Toast.makeText(getActivity(), "Already exits", Toast.LENGTH_LONG).show();
            }

        }

        contactAdapterMyEvents.setContactList(contactsList);
        myEventsAdapter.notifyItemChanged(result);

0 个答案:

没有答案