Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

java - How to pass ArrayList using putStringArrayListExtra()

Hi I want to pass an Arraylist from one activity to another. I use putStringArrayListExtra(), but there shows an error : "The method putStringArrayListExtra(String,ArrayList is undefined for the type bundle." Is there any other method available for passing ArrayList?

String test[]=new String[3]; 
ArrayList<String[]> al=new ArrayList<String[]>();  
int x,y;
test[0]="1";  
test[1]="2";  
test[2]="3";  
al.add(test);  

test = new String[3]; 
test[0]="4";  
test[1]="5";  
test[2]="6";  
al.add(test);  

Bundle list_bundle=new Bundle(); 
list_bundle.putStringArrayListExtra("lists",al); 
Intent list_intent= new Intent(v.getContext(), view_all_selected.class); 
list_intent.putExtras(list_bundle); 
startActivityForResult(list_intent, 2); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this It worked for me

1st Activity

ArrayList<String> ar=new ArrayList<String>();
ar.add("Apple");
ar.add("Banana");

Intent i=new Intent(this,Route.class);
i.putStringArrayListExtra("list", ar);
startActivity(i);

2nd Activity

ArrayList<String> ar1=getIntent().getExtras().getStringArrayList("list");   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...