1
A
回答
0
使用Ridcully解決方案,您將只需添加數據庫名稱部分, 所有你需要補充的是你擴展類。
你所提到的庫這個例子:
public class MyDatabase extends SQLiteAssetHelper {
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
// here comes the magic:
String dbName = context.getString(R.string.db_name);
super(context, dbName , null, DATABASE_VERSION);
}
}
的其他數據庫類可以是:
public class MyDatabase2 extends SQLiteAssetHelper {
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
// here comes the magic:
String dbName = context.getString(R.string.db_name_2);
super(context, dbName , null, DATABASE_VERSION);
}
}
注:使用SQLiteAssetHelper,u需要自己創建數據庫,放入資產/數據庫文件夾。
你可以用這個程序Sqlitebrowser
4
應該可以很容易當您提供與數據庫的名稱字符串資源:
在/res/values/strings.xml
把這樣一行:
<string name="db_name">database</string>
在/res/values-de/strings.xml
把該行:
<string name="db_name">database_de</string>
而在您的DBHelper類中,根據語言設置使用當前活動的字符串文件的數據庫名稱:
public class DBHelper extends SQLiteOpenHelper {
private final static int DB_VERSION = 1;
private static DBHelper sInstance;
/**
* Provides access to DBHelper singleton.
* @param context
* @return
*/
public static DBHelper getInstance(Context context) {
// Use the application context, which will ensure that you
// don't accidentally leak an Activity's context.
// See this article for more information: http://bit.ly/6LRzfx
if (sInstance == null) {
sInstance = new DBHelper(context.getApplicationContext());
}
return sInstance;
}
/**
* Constructor should be private to prevent direct instantiation.
* make call to static factory method "getInstance()" instead.
*/
private DBHelper(Context context) {
// here comes the magic:
String dbName = context.getString(R.string.db_name);
super(context, db_name, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
// ...
}
// ...
}
相關問題
- 1. 如何使用多種開發語言
- 2. Yii2多種語言
- 3. 多種語言+ Htaccess
- 4. Joomla多種語言
- 5. 在routes.php中使用多種語言
- 6. 如何在Android中使用多種語言
- 7. 如何使用Tesseract在Android上使用多種語言支持?
- 8. tcpdf中的多種語言
- 9. 多種語言的多種字體
- 10. Django-CMS中多種語言的方言
- 11. 跨多種語言搜索 - 如何?
- 12. 如何爲多種語言生成類
- 13. CFBundleLocalizations info.plist - 如何設置多種語言
- 14. 支持多種語言
- 15. 多種語言數據
- 16. Twitter4j - 多種語言的FilterQuery
- 17. 多種語言的網站
- 18. 多種語言的帖子?
- 19. cakePhp和多種語言
- 20. 流星:多種語言?
- 21. iphone uiaccessiblity多種語言
- 22. yii2基本多種語言
- 23. 多種語言模型
- 24. 翻譯爲多種語言
- 25. 多種語言的PHP preg_match
- 26. CruiseControl.net有多種語言?
- 27. 多種語言的網址
- 28. SOLR索引每種語言/多種語言的SQL數據
- 29. 如何用同一種語言實現一種語言比語言更快?
- 30. 以多種語言發言到文本
你也可以創建一個名爲'translations'您存儲所有的名字之類的東西不同的表創建SQLite數據庫。例如,如果您有一個帶有'productid'的表'product'的表'product_translations',並帶有'productid','languagekey'和翻譯列。 (只是我過去做過的一種方式) – Bram
你的意思是使用一個數據庫? – Hades10
是的,我只使用了一個數據庫,只有2個表。 – Bram