传递字符串数组ArrayList中从一个活动到另一个机器人 [英] Passing ArrayList of string arrays from one activity to another in android

查看:114
本文介绍了传递字符串数组ArrayList中从一个活动到另一个机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想字符串数组的ArrayList传递从一个活动到另一个机器人。
如何使用意图?请考虑 intent.putStringArrayListExtra 不工作在这种情况下,因为它不是为字符串数组。

I want to pass an ArrayList of string arrays from one activity to another in Android.
How can I use intent or bundle? Please consider that intent.putStringArrayListExtra is not working in this case, because it is not for string arrays.

推荐答案

不知道你所说的字符串数组ArrayList的的意思

Not sure what you mean by "ArrayList of string arrays"

如果您有字符串数组然后检查下面的链接

If you have string array then check the below link

<一个href="http://stackoverflow.com/questions/4429036/passing-string-array-between-android-activities">Passing Android的活动之间的字符串数组

<一个href="http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html">http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

ArrayList的工具序列化

ArrayList implements Serializable

您可以使用意图

    ArrayList<String> mylist = new ArrayList<String>();  
    Intent intent = new Intent(ActivityName.this, Second.class);
    intent.putStringArrayListExtra("key", mylist);
    startActivity(intent);

要检索

    Intent i = getIntent();  
    ArrayList<String> list = i.getStringArrayListExtra("key");

公共意向putStringArrayListExtra(字符串名称,ArrayList的&LT;字符串&GT;值)

添加扩展的数据的意图。该名称必须包括一个包preFIX,例如应用程序com.android.contacts将使用的名称,如com.android.contacts.ShowAll。

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

参数

name    The name of the extra data, with package prefix.
value   The ArrayList data value.

返回

Returns the same Intent object, for chaining multiple calls into a single statement.

要通过字符串数组的ArrayList

To pass ArrayList of String array

String[] people = {
        "Mike Strong",
        "Jennifer Anniston",
        "Tom Bennet",
        "Leander Paes",
        "Liam Nesson",
        "George Clooney",
        "Barack Obama",
        "Steve Jobs",
        "Larry Page",
        "Sergey Brin",
        "Steve Wozniak"
};
String[] people1 = {
        "raghu", 
        "hello"
};


ArrayList<String[]> list = new ArrayList<String[]>();
list.add(people);
list.add(people1);
Intent i = new Intent(MainActivity.this,SecondActivity.class);
i.putExtra("key", list);
startActivity(i); 

要检索

Intent in = getIntent();
ArrayList<String[]> list =(ArrayList<String[]>) in.getSerializableExtra("key");
for(int i=0;i<list.size();i++)
{
   String s[]= list.get(i);
   for(int iv=0;iv<s.length;iv++)
   Log.i("..............:",""+s[iv]);
}

这篇关于传递字符串数组ArrayList中从一个活动到另一个机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆