Skip to content Skip to sidebar Skip to footer

How To Search For Words In String.xml

I'm a beginner in android programming. I have a program with 10 layouts, within them 10 different tables. I use string.xml for text resources. I want to search in my program for di

Solution 1:

I want to search in my program for different words. And if I have a match, I want to set the layout that contains it. How can I do this?

You can't search for a word in a String situated in strings.xml unless you retrieve each String and test it. I think your best option is to store your strings in a sqlite database(along with a special integer to represent the table from which the string is) and then you could simply do a query with LIKE on the database to see if you get something(and return the special integer to set the layout as you want).

The other options are to either:

  • get at the start all the strings and store them in an array of arrays of strings(I don't know how well will this play regarding memory issues). Then you could simply check that string array for the particular word and do whatever you want.

  • or check all the strings for the particular word each time. This can be done using the getIdentifier method(assuming that the strings have special set ids(like yours)), but I think the performance will be awfull as the getIdentifier method is quite slow.

Post a Comment for "How To Search For Words In String.xml"