Tema: [ SOLUCIONADO ] Bases datos varios idiomas
Ver Mensaje Individual
  #11  
Viejo 26/10/15, 13:23:28
Avatar de mocelet
mocelet mocelet no está en línea
Desarrollador
Mensajes: 2,203
 
Fecha de registro: may 2011
Localización: Madrid
Mensajes: 2,203
Tu operador: -
Mencionado: 17 comentarios
Tagged: 2 hilos
Cita:
Originalmente Escrito por sonydei Ver Mensaje
Os pongo los dos archivos el que me funciona con una sola base de datos:
Código:
public static void initialize(SQLiteDatabase db, Context ctx) {
		// Initialize DB
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					ctx.getAssets().open("InitializeDB.txt"), "UTF-8"));

			// do reading, usually loop until end of file reading
			String mLine = reader.readLine();
			while (mLine != null) {
				// process line
				db.execSQL(mLine);
				mLine = reader.readLine();
			}

			reader.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
Y el modificado que no funciona con las modificiaciones que me habéis indicado.

Código:
public static void initialize(SQLiteDatabase db, Context ctx) {
		// Initialize DB
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					ctx.getAssets().open(getString("R.string.InitializeDB")), "UTF-8"));

			// do reading, usually loop until end of file reading
			String mLine = reader.readLine();
			while (mLine != null) {
				// process line
				db.execSQL(mLine);
				mLine = reader.readLine();
			}

			reader.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private static String getString(String string) {
		// TODO Auto-generated method stub
		return null;
	}
y este el string por ejemplo el español

Código:
<string name="InitializeDB">InitializeDB-es.txt</string>
¿Donde veis el fallo? Muchas gracias por vuestra ayuda.
O_O Eso no son las modificaciones que te comenté

Primero que has creado un método getString porque te ha parecido bien y devuelve null, cuando evidentemente me refería al método getString de Android para obtener recursos.

Segundo, sigues sin quitar las comillas a R.string.blablabla...

Escríbelo así para menos dudas:

Código:
ctx.getAssets().open(ctx.getString(R.string.InitializeDB)), "UTF-8"));
Responder Con Cita