【问题标题】:I want to pass String array to textView in another activity in android?我想在 android 的另一个活动中将字符串数组传递给 textView?
【发布时间】:2018-01-12 01:45:00
【问题描述】:

这是第一个活动

Intent intent = new Intent(Songs.this,PlayingSong.class);
Bundle bundle=new Bundle();
bundle.putStringArray("data",songs);
intent.putExtras(bundle);
startActivity(intent); 

这是第二个活动

tv = (TextView)findViewById(R.id.playingSongName);
imge = (ImageView)findViewById(R.id.playingImage);

Bundle bundle = getIntent().getExtras();

String[] arrRecd = bundle.getStringArray("data");
tv.setText(arrRecd[]);

【问题讨论】:

  • 那么你的问题是什么?它不工作吗? bundle 是否为空?有什么问题

标签: android android-layout listview


【解决方案1】:

您不能将字符串数组直接设置到 TextView。而是创建一个字符串并将其设置为 TextView。

String text = "";
for(int i = 0; i < arrRecd.length; i++) {
    text = text + arrRecd[i];
}
tv.setText(text);

【讨论】:

    【解决方案2】:

    在第一个活动中:

     Intent intent=new Intent(this,SearchActivity.class);
                intent.putStringArrayListExtra("data",songs);
                startActivity(intent);
    

    在第二个活动中:

     ArrayList<String> list=getIntent().getStringArrayListExtra("data");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多