将数据从recylerview适配器传递到导航抽屉中的片段

时间:2018-08-01 15:51:08

标签: android android-intent adapter recycler-adapter

我想将数据从recycleview适配器传递到片段,然后打开片段。我尝试了提到的东西,但是没有用。我应该将片段实现为片段还是将活动实现为片段?请提供解决方案。我该怎么办?

public class QuotationAdapter extends RecyclerView.Adapter<QuotationAdapter.ViewHolder>implements Filterable {
private Context context;
String id;
private List<ListQuotation> contactList;
private List<ListQuotation> contactListFiltered;
private QuotationAdapter.ContactsAdapterListener listener;
 Fragment fragment = new Fragment();

  @Override
public void onBindViewHolder(final QuotationAdapter.ViewHolder holder, int position) {
    final ListQuotation contact = contactListFiltered.get(position);
    holder.item_list_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            context = v.getContext();
            id = contact.getId();
           passData(id);

        }
    });

 }

private void passData(String id) {
    Intent intent = new Intent(context,QuotationItemDetails.class);
    intent.putExtra("id", ""+id);
   context.startActivity(intent);
}

这是我的片段

public class ItemListFragment extends Fragment {
String id;
TableLayout tv;
private static final String url = "";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    //returning our layout file
    //change R.layout.yourlayoutfilename for each of your fragments
    final View rootView =  inflater.inflate(R.layout.fragment_item_list, container, false);

    tv = (TableLayout)rootView.findViewById(R.id.tableexp);
    loadItemData();

    //get id
    id = getArguments().getString("id");
    return rootView;
}

0 个答案:

没有答案