开发者社区> 问答> 正文

如何将数组分解为不同的字符串

所以我将数组从一个活动传递到另一个活动,当我将数组发送到另一个活动时,我想将数组分解为各种字符串。例如 :

在第一次活动中:


array[] x = [car,ball,mouse,shirt]

在第二活动中:

接收x array [],然后将其分解为:

string one = "car"
string two = "ball"
string three = "mouse"
string four = "shirt"

因此,例如,我可以分别对其中的每个使用Toast操作。

这是我的实际代码:

头等舱:

Bundle b=new Bundle();
b.putStringArray("key",new String[]{repeat,temp,humidit,activer,food});
Intent i=new Intent(recruiter.this, StructureClass.class);
i.putExtras(b);

二等舱:

Bundle b = this.getIntent().getExtras();
final String[] array= b.getStringArray("key");



Toast.makeText(StructureClass.this, "i want the string to be shown here 
separately for each value! " , Toast.LENGTH_LONG).show();

展开
收起
Puppet 2020-01-12 09:18:55 361 0
1 条回答
写回答
取消 提交回答
  • 我认为这段代码可以为您提供帮助。

    
        final String[] array= b.getStringArray("key");
        String a="";
        for (String b: s) {
            a+=b+", ";
        }
        Toast.makeText(StructureClass.this, a , Toast.LENGTH_LONG).show();
    
    2020-01-12 09:19:15
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载