1

私は、別のrecyclerview(B)を含むリサイクラービュー(A)を持っています。 recyclerview(A)アイテムのプラスアイコンをクリックすると、recyclerview(C)で新しいアクティビティが開きます。長く押すと、いくつかの項目を選択し、完了をクリックします。これは、私がplusアイコンをクリックしたrecyclerview(A)アイテムのrecyclerview(B)を更新する必要があります。RecyclerView with recyclerView with ActivityOnresult

代わりに、recyclerview(B)を含むrecyclerview(A)のすべての項目が更新されています。

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

} 



class RecyclerAdapterUpcomingEvents extends RecyclerView.Adapter<RecyclerAdapterUpcomingEvents.MyViewHolder> { 

    private List<UpcomingEvents> upcomingEventsList; 
    private Context context; 
    private LayoutInflater inflater; 


    RecyclerAdapterUpcomingEvents(Context context, List<UpcomingEvents> upcomingEventsList) { 
     this.context = context; 
     this.upcomingEventsList = upcomingEventsList; 
     inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

     View rootView = inflater.inflate(R.layout.card_view_upcoming_event, parent, false); 
     return new RecyclerAdapterUpcomingEvents.MyViewHolder(rootView); 
    } 

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

     UpcomingEvents upcomingEvents = upcomingEventsList.get(position); 

     holder.eventUpcomingName.setText(upcomingEvents.getEventUpcomingName()); 
     holder.eventUpcomingType.setText(upcomingEvents.getEventUpcomingType()); 
     holder.eventUpcomingDate.setText(upcomingEvents.getEventUpcomingDateStart() + upcomingEvents.getEventUpcomingDateEnd()); 
     holder.eventUpcomingMonth.setText(upcomingEvents.getEventUpcomingMonthEnd() + upcomingEvents.getEventUpcomingMonthEnd()); 
     holder.eventUpcomingAlarmNotify.setText(upcomingEvents.getEventUpcomingAlarmNotify()); 
     holder.eventUpcomingPlace.setText(upcomingEvents.getEventUpcomingPlace()); 

     holder.eventUpcomingAddPeople.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Activity origin = (Activity) context; 
       origin.startActivityForResult(new Intent(getAppContext(), ContactsActivity.class), CONTACT_CODE); 
      } 
     }); 


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

    } 


    @Override 
    public int getItemCount() { 
     return upcomingEventsList.size(); 
    } 

    class MyViewHolder extends RecyclerView.ViewHolder { 

     private TextView eventUpcomingName, eventUpcomingType, eventUpcomingDate, eventUpcomingMonth, eventUpcomingAlarmNotify, eventUpcomingPlace, eventUpcomingYes, eventUpcomingInterested, eventUpcomingNo; 
     private ImageView eventUpcomingAddPeople, eventUpcomingmore; 
     private RecyclerView contactRecyclerView; 


     MyViewHolder(View itemView) { 
      super(itemView); 
      eventUpcomingName = (TextView) itemView.findViewById(R.id.event_name); 
      eventUpcomingType = (TextView) itemView.findViewById(R.id.event_type); 
      eventUpcomingDate = (TextView) itemView.findViewById(R.id.event_date); 
      eventUpcomingMonth = (TextView) itemView.findViewById(R.id.event_month); 

      eventUpcomingAlarmNotify = (TextView) itemView.findViewById(R.id.event_time_notify); 
      eventUpcomingPlace = (TextView) itemView.findViewById(R.id.event_place); 

      eventUpcomingYes = (TextView) itemView.findViewById(R.id.event_yes); 
      eventUpcomingInterested = (TextView) itemView.findViewById(R.id.event_interested); 
      eventUpcomingNo = (TextView) itemView.findViewById(R.id.event_no); 

      eventUpcomingmore = (ImageView) itemView.findViewById(R.id.event_more); 
      eventUpcomingAddPeople = (ImageView) itemView.findViewById(R.id.hex_one_event); 

      contactRecyclerView = (RecyclerView) itemView.findViewById(R.id.upcome_events_recycler); 

     } 
    } 
} 



@Override 
public void onReceived(int requestCode, int resultCode, Intent data) { 

    if (requestCode == CONTACT_CODE && resultCode == RESULT_OK && data != null) { 

     List<Contact> contactsLists = (ArrayList<Contact>) data.getSerializableExtra("contacts"); 
     contactsList.clear(); 
     contactsList.addAll(contactsLists); 

     contactAdapter.setContactList(contactsLists); 

     upcomingEventsAdapter = new RecyclerAdapterUpcomingEvents(getContext(), upcomingEventsArrayList); 
     RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getAppContext()); 
     recyclerView.setLayoutManager(mLayoutManager); 
     recyclerView.setHasFixedSize(true); 
     recyclerView.setAdapter(upcomingEventsAdapter); 
    } 
} 

CardView

 <android.support.v7.widget.RecyclerView 
      android:id="@+id/upcome_events_recycler" 
      android:layout_width="match_parent" 
      android:layout_height="52dp" 
      android:layout_below="@id/event_place" 
      android:layout_marginBottom="8dp" 
      android:layout_marginEnd="52dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="8dp"> 

     </android.support.v7.widget.RecyclerView> 

     <ImageView 
      android:id="@+id/hex_one_event" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:layout_alignParentEnd="true" 
      android:layout_below="@id/event_place" 
      android:layout_margin="8dp" 
      android:src="@drawable/hex_src_plus" /> 

For better understanding

+0

私はよくあなたの問題を理解していないが、私はあなたが、アレイ内の選択された位置を入れて、それが助けにのみ、このpositions.Hopeを更新するべきだと思います:)役立ちます願っています。 – Rockers23

+0

ありがとうございます...あなたは正しいです@ Rockers23しかし、それを行う方法を得るイムニット –

+0

私はあなたが同じ時間にrecyclerview Bを含む1つまたは複数のアイテムを編集するかどうかを知る必要がありますか?私はあなたの長いプレス方法とあなたのリサイクルビューの更新方法を見てもらう必要があります。 – Rockers23

答えて

1

まず下記これにより、あなたのコードを変更:あなたはDoneをクリックしたときにそのような何かを持っている必要があり二活性に

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); 
} 
} 

int param = getIntent().getIntExtra("selectedPosition"); 
Intent resultIntent = new Intent(); 
resultIntent.putExtra("contacts", Your selected contacts); 
resultIntent.putExtra("selectedPosition", param); 

setResult(RESULT_OK, resultIntent); 
finish(); 

はそれを明確にし、

+0

私はアクティビティ→フラグメント→フラクションBを持っています。 ..折り返しデータを処理する方法 –

+0

recyclerView AはフラグメントAにあり、フラグメントBにはrecyclerView Cが含まれていますか? – Rockers23