0
votes

i want to call getIntent().getStringExtra() inside this adapter class. I passed username in my previous class. but here I can't call get intent in this adapter class. @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.layout_gig_item, parent, false);

        return new ViewHolder(itemView);
    }


    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {

        final GigHolder gigHolder = gigList.get(position);

        holder.lbl_title.setText(gigHolder.getTitle());
        holder.lbl_price.setText(Utils.getDecimal(gigHolder.getTotal()));
        holder.lbl_contact.setText(gigHolder.getContact());
        holder.img_cover.setImageURI(gigHolder.getImage());
        holder.ll_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

               if(!isAdminView){
                   Intent intent = new Intent(activity, GigViewActivity.class);
                   intent.putExtra(Constants.BUNDLE_ID, gigHolder.getPrimaryKey());
                   activity.startActivity(intent);
               }

            }
        });

    }


}
2

2 Answers

0
votes

It would be better to just get the data from the activity or fragment supporting the adapter class and pass it to the adapter class through a function

0
votes

You have two ways to solve this issue:

First way is to pass the Context of the calling Class as a Constructor parameter of the Adapter. You can then access the StringExtra by calling context.getIntent().getStringExtra().

Second way is to get the StringExtra from your calling Class and then pass it as a Contructor parameter of the Adapter.