public class BobDatabase extends SQLiteOpenHelper{
private static final String DATABASE_NAME = "bob.db";
private static final int DATABASE_VERSION = 1;
public static final String DEFAULT_PROFILE = "default_profile";
public BobDatabase(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database)
{
createProfileTable(database);
createTimeTable(database);
createEventTable(database);
createLocationTable(database);
}
/**
* Creates a table for Profile objects, executes the string create_profile_table_sql
* contained within strings.xml
* @param database
*/
public void createProfileTable(SQLiteDatabase database)
{
database.execSQL(Resources.getSystem().getString(R.string.create_profile_table_sql));
}}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
01-14 12:20:57.591:E/AndroidRuntime(1825):引起:android.content.res.Resources $ NotFoundException:字符串资源ID#0x7f040003
导致错误的代码是createProfileTable中的单行,具体是Resources.getSystem().getString(R.string.create_profile_table_sql) …
我正在使用a ArrayList并且所有字符串都在适配器中进行了硬编码,但现在我需要为我的应用程序提供多语言支持.我认为最好的方法是将我的所有硬编码字符串移动到我的strings.xml文件,然后生成我需要的所有不同语言的字符串文件.
我已经将硬编码的字符串移动到我的strings.xml但我现在不确定如何调用它们Arraylist而不是在那里使用硬编码字符串.
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
List<AdapterData> mItems;
public Adapter() {
super();
mItems = new ArrayList<>();
AdapterData data = new AdapterData();
data.setQuestion("How Old Are You?");
data.setAnswer("I Am 21 Years Old");
mItems.add(data);
data = new AdapterData();
data.setQuestion("Where Were You Born?");
data.setAnswer("I Was Born In The USA");
mItems.add(data);
data = new AdapterData();
data.setQuestion("Are You Male or Female?");
data.setAnswer("I Am Male");
mItems.add(data);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.recycler_view_card_item, viewGroup, …Run Code Online (Sandbox Code Playgroud) 这是以编程方式设置文本的正确方法吗TextView?
points_txt.setText(R.string.you_have + current_points + R.string.points);`
Run Code Online (Sandbox Code Playgroud)
它向我显示了该字符串的 ResourcesNotFoundException 错误,而我可以在 strings.xml 文件中看到该字符串。