【发布时间】:2013-02-27 20:22:48
【问题描述】:
所以,我在网上搜索了很多我不需要的例子......
这是我的情况:
假设您有一个资源,它是一个名为 song 的数组,每个歌曲名称都有许多 's ..所以,假设您在列表视图中显示了 200 个歌曲名称..
当您单击一首歌曲时,该应用会加载另一个带有该歌曲歌词的活动... 但是你是怎么做到的呢?
我是这样做的。我将歌曲的名称传递给这个新活动,加载了歌词所在的资源...
但是,当我必须用歌词设置文本时,我遇到了一个问题......我应该用 200 个案例进行切换吗?这听起来很疯狂,所以,我所做的是,我在歌词中使用了相同的歌曲名称..所以它应该像这样加载:
TextView txtProduct = (TextView) findViewById(R.id.product_label);
Intent i = getIntent();
// getting attached intent data
String[] musicas = getResources().getStringArray(R.array.botafogo_songs);
// this here is where it brings the name of the music to the activity
String product = i.getStringExtra("product");
// displaying selected product name
if (Arrays.asList(musicas).contains(product)) {
//just formating so they have the same name.
String productSplit = product.split("- ")[1];
productSplit.replace(" ", "");
txtProduct.setText(getString(R.string.AbreAlas));
}else{
txtProduct.setText("não contem");
}
好的,AbreAlas 是我的资源的名称..它加载正常..
但是,我不能这样离开它......它应该是一个变量名......
喜欢:R.string.+productSplit
或类似的东西..
我无处可寻..
【问题讨论】:
标签: java android mobile gettext settext