Hi我想用这个方法向字符串数组添加新字符串,但它不起作用,因为当我开始新活动时,favaorites数组不会更新。为什么?
Resources res = getResources();
String[] favorites = res.getStringArray(R.array.favorites);
String[] planets = res.getStringArray(R.array.planets_array);
String[] temp = new String[favorites.length+1];
System.arraycopy(favorites,0,temp,0,favorites.length);
temp[favorites.length] = planets[mCounter];
favorites = temp;
在您的情况下,您可以使用SharedPreferences将字符串存储到其中。不需要数组赋值,这是一种更干净的方法。一些链接可以帮助您开始:
-
http://saigeethamn.blogspot.in/2009/10/shared-preferences-android-developer.html
-
http://saigeethamn.blogspot.in/2009/10/shared-preferences-android-developer.html
- http://developer.android.com/guide/topics/data/data-storage.html
要解决您的问题,您应该创建一个包含所有这些属性的SQLite数据库。然后,您应该从Cursor中检索它们(在查询数据库后),并根据需要使用
另一个注意事项是,不能添加到已经定义的R.array.*中,因为它是预编译的资源。