1

I have two String list to send to an activity from an adapter in android.

I have these two arrays in my adapter,

 private final List<String> toppingPriceTop;
 private final List<String> toppingDescriptionTop;

and in my adapter I have this button, this button click sending these details to the activity,

customize.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {

                Intent next = new Intent(context, ActivityCustomize.class);

                next.putExtra("description", descriptions.get(position));
                next.putExtra("imageUrl", imageUrls.get(position));

                next.putExtra("toppingDescriptionTop", toppingDescriptionTop.get(position));
                next.putExtra("toppingPriceTop", toppingPriceTop.get(position));

                context.startActivity(next);
                ((Activity) context).overridePendingTransition(
                        R.anim.slide_in_right, R.anim.slide_out_left);
            }

In my activity I'm receiving these data as,

String [] toppingPriceTop = getIntent().getStringArrayExtra("toppingPriceTop");
String [] toppingDescriptionTop = getIntent().getStringArrayExtra("toppingDescriptionTop");
String imageUrl = getIntent().getStringExtra("imageUrl");
String  description = getIntent().getStringExtra("description");

My problem is I'm getting values for imageUrl and description in the activity but for both the list arrays I'm getting null. an anyone tell me where I have gone wrong and how can I correct this please. Any help will be appreciated.

1 Answer 1

3

do it like

 next.putStringArrayListExtra("toppingDescriptionTop", toppingDescriptionTop);
 next.putStringArrayListExtra("toppingPriceTop", toppingPriceTop);

You Should pass all List

and get it like

List<String> toppingPriceTop = getIntent().getStringArrayListExtra("toppingPriceTop");
List<String> toppingDescriptionTop = getIntent().getStringArrayListExtra("toppingDescriptionTop");

OR

do it like

 Bundle b=new Bundle();
 b.putStringArrayListExtra("toppingPriceTop ", toppingPriceTop);
 b.putStringArrayListExtra("toppingDescriptionTop", toppingDescriptionTop);
 next.putExtras(extras)
 context.startActivity(next);

and get it like:

 Bundle b=getIntent().getExtras();
 ArrayList<String> toppingPriceTop =b.getStringArrayList("toppingPriceTop");
 ArrayList<String> toppingDescriptionTop =b.getStringArrayList("toppingDescriptionTop");
Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting this error in my adapter, The method putStringArrayListExtra(String, ArrayList<String>) in the type Intent is not applicable for the arguments (String, List<String>)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.