title: How to create a interface in main activity and pass the data from adapter to main activity through the interface?
body: <p>I have created a RecyclerView in my fragment one and I have created a RecyclerViewAdapter to bind my date set to views that are displayed within the RecyclerView in my fragment one. I have loaded my fragment one in my main activity. Now I have a problem is that I need to create an interface in the main activity and pass the data from my adapter to main activity through the interface so that I can wrap the data into bundle and load fragment two. But i do not know how to do this. Can someone help me?</p>
  
  <p>Here is my main activity.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      FragmentOne fragmentOne = new FragmentOne();
      FragmentManager fragmentManager = getSupportFragmentManager();
      fragmentManager.beginTransaction().add(R.id.fragment_container,fragmentOne).commit();
  
  }}
  </code></pre>
  
  <p>Here is my Fragment One.</p>
  
  <pre><code>public class FragmentOne extends Fragment {
  public RecyclerView recyclerView;
  public ArrayList&lt;Promotion&gt; promotionArrayList;
  public MyAdapter myAdapter;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_fragment_one, container, false);
      recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);
      recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      DividerItemDecoration divider = new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL);
      recyclerView.addItemDecoration(divider);
      promotionArrayList = Promotion.createPromotionList();
      myAdapter = new MyAdapter(promotionArrayList);
      recyclerView.setAdapter(myAdapter);
      return view;
  }}
  </code></pre>
  
  <p>Here is my adapter.</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
  public ArrayList&lt;Promotion&gt; promotionArrayList;
  
  
  public MyAdapter(ArrayList&lt;Promotion&gt;promotionArrayList) {
      this.promotionArrayList = promotionArrayList;
  }
  
  @NonNull
  @Override
  public MyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
      View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout,viewGroup,false);
      return new ViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
      Promotion promotion = promotionArrayList.get(i);
      viewHolder.imageView.setImageResource(promotion.getImgId());
      viewHolder.promotion_period.setText(promotion.getPromotion_period());
      viewHolder.promotion_deals.setText(promotion.getPromotion_deals());
      viewHolder.shop_name.setText(promotion.getShop_name());
  }
  
  @Override
  public int getItemCount() {
      return promotionArrayList.size();
  }
  
  public static class ViewHolder extends RecyclerView.ViewHolder{
  
      public TextView shop_name,promotion_deals, promotion_period;
      public ImageView imageView;
  
      public ViewHolder(@NonNull View itemView) {
          super(itemView);
          shop_name = (TextView)itemView.findViewById(R.id.shop_name);
          promotion_deals = (TextView)itemView.findViewById(R.id.promotion_deals);
          promotion_period = (TextView)itemView.findViewById(R.id.promotion_period);
          imageView = (ImageView)itemView.findViewById(R.id.imageView);
      }
  }}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5k0dn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5k0dn.png" alt="This is what i want to do"></a></p>