开发者_Python百科I have a listview say in this instance has the values:
UK, USA, FRANCE
These values are pulled from a static array held within my string.xml file. Additionally, within the string.xml is 3 arrays each referring to UK, USA and FRANCE & basically I want to load these arrays into a new listview depending on the users onclick event.
Essentially I dont know how to pass the users selection to the new listview and populate accordingly. I know the process incorporates the use of an intent but being an android newbie I am not exactly sure how!
Any help is much appreciated!
Cheers
First Context (can be Activity/Service etc)
You have a few options:
1) Use the Bundle from the Intent:
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);
2) Create a new Bundle
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);
3) Use the putExtra() shortcut method of the Intent
Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);
New Context (can be Activity/Service etc)
Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
String value = myIntent.getExtras().getString(key);
}
NOTE: Bundles have "get" and "put" methods for all the primitive types, Parcelables, and Serializables. I just used Strings for demonstrational purposes.
精彩评论