问题
I have a 'Fragment' which has a vertical RecyclerView
, inside every item of the RecyclerView
there is a horizontalRecyclerView
with an add button. On clicking the Add button startActivityOnResult
is called. The values on the onActivityResult
have to update the horizontal RecyclerView
in the particular view where I clicked add button.
I have achieved almost everything but what's happening is when I update the horizontal RecyclerView
, all the vertical view items horizontal RecyclerView
is getting updated.
In Fragment
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);
}
And in adapter 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);
}
In fragment how should i receive this data please
OnActivity Result
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);
来源:https://stackoverflow.com/questions/45009786/horizontal-recycler-view-inside-vertical-recycler-view-inside-a-fragment-with-on