Java 如何从strings.xml到arraylist获取值
我有以下代码:Java 如何从strings.xml到arraylist获取值,java,android,string,arraylist,key-value,Java,Android,String,Arraylist,Key Value,我有以下代码: package com.sample.app; import android.content.res.Resources; import java.util.ArrayList; public class Content { public static ArrayList<String> Names; public static ArrayList<String> NamesSub; public static Arr
package com.sample.app;
import android.content.res.Resources;
import java.util.ArrayList;
public class Content {
public static ArrayList<String> Names;
public static ArrayList<String> NamesSub;
public static ArrayList<String> Images;
public static ArrayList<String> Wallpaper;
public static ArrayList<String> Audio;
public static ArrayList<String> BIG_Images;
public static ArrayList<String> Sub_heading;
public static ArrayList<String> Description;
Content(){
this.Names = new ArrayList<String>();
this.NamesSub = new ArrayList<String>();
this.Sub_heading = new ArrayList<String>();
this.Images = new ArrayList<String>();
this.Wallpaper = new ArrayList<String>();
this.BIG_Images = new ArrayList<String>();
this.Audio = new ArrayList<String>();
this.Description = new ArrayList<String>();
this.Description.add(0, "Long description");
this.Description.add(1, "");
this.Description.add(2, "");
}
}
但是当我运行这个应用程序时,它会打印像这样的数字2131689519
而不是我的值
之后我尝试了字符串数组
<string-array name="descvalue">
<item>too long value</item>
</string-array>
但当我运行应用程序时,它崩溃了
那么在这种情况下我该怎么办?谢谢。“错误:常量字符串太长”
为此,您可以使用文本类
Text text = new Text("foo");
String s = text.getText();
text.setText(s);
“错误:常量字符串太长”
为此,您可以使用文本类
Text text = new Text("foo");
String s = text.getText();
text.setText(s);
替换
this.Description.add(0,String.valueOf(R.string.descvalue));
与
但是getString()
需要一个上下文
替换
this.Description.add(0,String.valueOf(R.string.descvalue));
与
但是
getString()
需要一个context
java中常量字符串的长度在编译时被限制为64K。java中常量字符串的长度在编译时被限制为64K。你能给我举个例子吗?对不起,我是Java的新手,你能给我举个例子吗?很抱歉,我是javagetString的新手,我想我应该添加一些代码,对吗?如何添加上下文您可以从活动、片段或应用程序类获取上下文对象,具体取决于您将代码放在何处。getString变为红色,我想我应该添加一些代码,对吗?如何添加上下文您可以从活动、片段或应用程序类中获取上下文对象,具体取决于您将代码放在何处。
this.Description.add(0,getString(R.string.descvalue));