I've created a list and would like to pass the list to another activity but i'm getting an error on the putExtra statement when i create the intent. Just wondering is there any easy way to pass a List of Strings rather than a single String?
Thanks
private List<String> selItemList;
private ListView mainListView = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipes);
Button searchBtn = (Button) findViewById(R.id.searchButton);
searchBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (selItemList == null) {
Toast.makeText(getApplicationContext()," Please Make A Selection ", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(Recipes2.this, XMLParser.class);
intent.putExtra("items_to_parse", selItemList);
startActivityForResult(intent, 0);
}
}
});
I know it is a little late and this question has an answer already but here is another way.
simply create another object define it as
Serializable
and give it a list variable and send that usingputExtra
on yourintent
like this:and then for sending it do this:
and to get the object you have created do this:
You can't pass a List in
Intent.putExtras(String name, List<?> list);
. I think you can use anArray
ofString
and pass it inputExtras
like this:You can use
putStringArrayListExtra
fromIntent
And in your XMLParser.class: