在Android应用程序传递了两个类之间的String数组 [英] Passing String array between two class in android application

查看:128
本文介绍了在Android应用程序传递了两个类之间的String数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我不知道如何通过两级之间的字符串数组。我试图意图,通过共享类的字符串数组,但我得到的只有一根弦,就不会显示该字符串的其余部分。我的一些朋友说,使用捆绑就可以访问类的字符串数组,但我不知道如何使用捆绑功能。任何人都可以指导我如何通过字符串数组。

I am new to android. i dont know how to pass string array between two class. I tried Intent, by sharing string array between the class, but i get only one string, the rest of the string will not displayed. Some of my friend said, using Bundle we can access string array between the class, but i dont know how to use the bundle function. can anyone guide me how to pass the string array.

推荐答案

如果您正试图从一个活动发送一个字符串转换成另一本可以在Intent来完成。

If you are trying to send a String-array from one Activity to another this can be done in the Intent.

在ClassA的:

Intent intent = new Intent(this, ClassB);
String[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);

在ClassB的:

public void onCreate() {
  Intent intent = getIntent();
  String[] myStrings = intent.getStringArrayExtra("strings");
}

这篇关于在Android应用程序传递了两个类之间的String数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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