0
    Intent i = getIntent();
    Bundle myBundle = i.getExtras();
    date1 = myBundle.getString("Date1");
    date2 = myBundle.getString("Date2");
    user = myBundle.getString("UserName");
    chain = myBundle.getString("ChainName");
    shop = myBundle.getString("ShopName");
    product_g = myBundle.getString("ProductGroup");
    product_c = myBundle.getString("ProductCategory");
    product = myBundle.getString("Product");
    count = myBundle.getInt("Count");
    type_c = myBundle.getInt("CountType");
    price = myBundle.getInt("Price");
    type_p = myBundle.getInt("PriceType");
    inch = myBundle.getInt("Inch");
    promotor = myBundle.getInt("Promotor");

I need these variables in recycler adapter to make retrofit request in RecyclerView adapter.

     holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder mBuilder = new android.app.AlertDialog.Builder(context);
            LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View mView = li.inflate(R.layout.sales_filtered_shop_pop_up, null);
            final RecyclerView rd3 = (RecyclerView) mView.findViewById(R.id.sales_rv);
            Button mClose = (Button) mView.findViewById(R.id.sales_pop_up_btn_close);
            mBuilder.setView(mView);
            final android.app.AlertDialog dialog = mBuilder.create();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);

            // here 
            dialog.show();

            mClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }
    });

This is my RecyclerView adapter item click. I need the variables in // here to make Retrofit api call.

Daniil Pavlenko
  • 153
  • 1
  • 9
Mert Malaves
  • 43
  • 1
  • 7
  • 1
    never make a request (or other background thread action) in an adapter. It's not the responsability of the adapter to do that. You must do the request in your activity ! To do that you can use an interface in your adapter and implemented this in your activity or use for exemple a library like EventBus to send event from your Adapter to your activity – SebastienRieu Dec 23 '19 at 16:32

3 Answers3

1

Intents are for communication between activity, what you need to do is to create a simple function in your adapter, and then call in the activity.

Adapter:

private String date1;
private String date2;

public void setData(String date1, String date2, ...) {
   this.date1 = date1;
   this.date2 = date2;
   ...
}

Activity:

 adapter.setData(date1, date2, ..);
DoubleD
  • 148
  • 10
1

(I can't use the comment yet but) The idea which @DoubleD wrote is the right one, all you need to do is to create a function (much like a constructor) that will receive your data in the adapter class. The NullPointerException you are getting isn't from the function, check your data. And I will suggest to create a custom object that will hold those things (depend on your goal).

newInteger
  • 43
  • 1
  • 10
1

Check this answer. Here you will have your onClickListener() in your Activity.

Simple Android RecyclerView example

Daniil Pavlenko
  • 153
  • 1
  • 9