【问题标题】:passing Entire ArrayList<String> from one activity to other in android将整个 ArrayList<String> 从一个活动传递到 android 中的另一个活动
【发布时间】:2012-10-23 12:00:56
【问题描述】:

我想将一个 ArrayList 从一个活动传递到另一个活动。 我发现这个pass arraylist from one activity to other 的链接很有用。

但是当我使用时

    ArrayList<String> hyperlinks = new ArrayList<String>();
                           ...

    Intent myIntent=new Intent(Player.this,VideoActivity.class);
                    Bundle mBundle = new Bundle();  
                    mBundle.putStringArrayListExtra("hyperlinks", hyperlinks);
                    //mBundle.putString("filePath", hyperlinks.get(0));  
                    myIntent.putExtras(mBundle); 
                    Player.this.startActivity(myIntent);

然后我在 mBundle.putStringArrayListExtra 处遇到错误, 说 方法 putStringArrayListExtra(String, ArrayList) 对于类型 Bundle 是未定义的

请指导我如何做到这一点?

谢谢

【问题讨论】:

标签: android android-intent arraylist


【解决方案1】:

有很多方法可以做到,但你试过了吗:

myIntent.putStringArrayListExtra(key, hyperlinks);

另外,Bundle 对象有

 putStringArrayList

【讨论】:

    【解决方案2】:

    检查应用程序。您可以扩展自己的应用程序,并在此处保存数组列表

    签出 ==> Extending Application to share variables globally

    【讨论】:

      【解决方案3】:

      Bundle 文档清楚地表明 putStringArrayList(String, ArrayList) 是 Bundle 类的方法,但不是 putStringArrayListExtra()

      http://developer.android.com/reference/android/os/Bundle.html#putStringArrayList(java.lang.String, java.util.ArrayList)

      另外,请检查导入声明,并检查是否已导入Proper Bundle 类

      Bundle类的包应该是:

      import android.os.Bundle;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-15
        • 1970-01-01
        • 1970-01-01
        • 2023-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多