简体   繁体   中英

Pass ArrayList<Double> from one activity to another activity on android

I've stored ArrayList<Double> on my bean class,

I've the bean class on my main activity,

How to pass the ArrayList<Double> ,from my main activity to another activity.?

My array list is double. how to pass double arraylist ?

This one helps you...

public Intent putParcelableArrayListExtra (String name, ArrayList<? extends Parcelable> value)

For more info look at putParcelableArrayListExtra

EDIT:

If you have a double[] then you can use

void putDoubleArray(String key, double[] value) of Bundle class..

Inserts a double array value into the mapping of this Bundle, replacing any existing value for the given key. And pass this bundle to Intent to Other Activity.

Update:2

FirstActivity:

Intent intent = new Intent(this, OtherActivity.class);
ArrayList<Double> listDouble = new ArrayList<Double>();
listDouble.add(1111.00000);
listDouble.add(13331.00000);
intent.putExtra("arraylist", listDouble);
startActivity(intent);

OtherActivity: (Retrieve Double ArrayList)

ArrayList<Double> listDouble = (ArrayList<Double>) getIntent().getSerializableExtra("arraylist");
System.out.println("...serialized data.." + listDouble);

Refer below method to pass data from one activity to other

Eg 1

putIntegerArrayListExtra(String name, ArrayList<Integer> value)
putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
putStringArrayListExtra(String name, ArrayList<String> value)
putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value)

Then you can read from you next activity by replacing put with get with key string as argument,eg

myIntent.getStringArrayListExtra("array");

Eg 2

Intent i = new Intent(this,name.class);
Bundle b = new Bundle();
b.putIntegerArrayListExtra(String name, ArrayList<Integer> value);
//b.putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value);
//b.putStringArrayListExtra(String name, ArrayList<String> value);
i.putExtra(String name,b);
startActivity(i);

您应该考虑通过Intent Extras将参数传递给其他活动:

Intent.putExtra() 

This code will demonstrate that how to pass a double array object to other activity through inent

String [] my_dblArray=new Sting[no];
   //put some value in the array and then pass through intent
Intent intnt=new Intent(this,YourReqActivity.class);            
Bundle bundle = new Bundle();
bundle.putDoubleArray("doubleVal",my_dblArray);  
intnt.putExtra(bundle);
startActivity(intnt);

// At Receiver side put this line of code.

 String [] dblval=Bndl.getDoubleArray("doubleVal");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM