Hi,
I try to get the value of a parameter from another activity, but can't
succeed in doing that. I found things about putExtra/getExtra, but
couldn't get it to work unfortunately.
Problem:
I've got a TabActivity called "methodes", which has a TabHost. The
contents of the Tabs are activities, and I need to retrieve in these
activities the value of maValeur (which is actually a
ArrayList<String>). My application is "net.sebeto.android.essai".
public class Methodes extends TabActivity
{
public static ArrayList<String> maValeur;
public void onCreate(Bundle savedInstanceState)
{
// I initialize "maValeur", ...
(...)
// MethTab2 will be the content of the second tab
Intent Tab2 = new Intent(this, MethTab2.class);
Tab2.putStringArrayListExtra
("net.sebeto.android.essai.Methodes.maValeur", maValeur);
TabHost host = getTabHost();
(...)
host.addTab(host.newTabSpec("two").setIndicator
("Valeur").setContent(Tab2));
}
}
Now:
public class MethTab2 extends Activity
{
private ArrayList<String> maValeurBis;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// How to get the value of maValeur??
// I found no way to use getStringArrayList?
// maValeurBis = savedInstanceState.getStringArrayList
("net.sebeto.android.cuisine.Methodes.maValeur"); crashes, ...
// I can get the value with maValeurBis =
Methodes.maValeur; but I'm not sure that it's
// a good way to do it, is it? It works, but... do you
think it's a good method?
maValeurAdapter = new ArrayAdapter<String>(this,
R.layout.methtab2,maValeurBis);
ListView list = new ListView(this);
list.setAdapter(maValeurAdapter);
list.setSelector(android.R.color.transparent);
setContentView(list);
}
}
Thank you for your answers, I'm a perfect beginner in java and in
android... If someone could give me a code which would work it would
be great! I know that it's probably very simple but...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---