Get String from strings.xml file

1

I'm trying to retrieve a String from the strings.xml file for this SQL_CID variable.

<string name="insert_cid">"
    INTO 'CID' ('COD_CID', 'NOME_CID', 'CODIGO_CID') VALUES(1, 'CÓLERA DEVIDA A VIBRIO CHOLERAE 01, BIÓTIPO CHOLERAE', 'A000'),(2, 'CÓLERA DEVIDA A VIBRIO CHOLERAE 01, BIÓTIPO EL TOR', 'A001'),(3, 'CÓLERA NÃO ESPECIFICADA', 'A009'),(4, 'FEBRE TIFÓIDE', 'A010'),(5, 'FEBRE PARATIFÓIDE A', 'A011')
</string>

JAVA:

String SQL_CID = Resources.getSystem().getString(R.string.insert_cid);
db.execSQL(SQL_CID);

But it is giving error.

    
asked by anonymous 22.02.2018 / 22:28

1 answer

1

You should use:

  • in an Activity or Service

    String SQL_CID = getString(R.string.insert_cid);
    
  • In another location, you need to have a Context

    String SQL_CID = myContext.getString(R.string.insert_cid);
    

Resources.getSystem().getString() only accesses system resources, does not access application resources as is the case.

    
22.02.2018 / 22:57