0

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 different words. And if I have a match, I want to set the layout that contains it. How can I do this?

<string name="table1_1">Kóros mértékben és tartósan <b>emelkedett, expanzív vagy irritábilis hangulat,</b> amely jól elhatárolható periódusban, legalább <b>1 héten át fennáll</b>(vagy bármeddig, ha kórházi felvétel szükséges).</string>
<string name="table1_2">A hangulatzavar időtartama alatt <b>az alábbi tünetek közül három (vagy több)</b> (irritált hangulat esetében négy) tünet az alábbiakból tartósan és jelentős mértékben fennáll: \n \n- felfokozott önértékelés vagy grandiózitás, \n- csökkent alvásigény (pl. 3 óra alvás után is kipihentnek érzi magát), \n- szokatlan beszédesség vagy folyamatos beszédkényszer (logorrhoea), \n- fellazult gondolkodás vagy gondolatrohanás, \n- szétszórtság (pl. a figyelem elhanyagolható, lényegtelen külső ingerekkel könnyen elterelhető), \n- fokozott célirányos aktivitás (társas érintkezés, munka/iskola, szexualitás területén), illetve pszichomotoros agitáltság, nyugtalanság, \n- olyan élvezetet vagy izgalmat okozó cselekedetek halmozása, amelyek meglehetősen nagy kozkázatot hordoznak magukban (pl. féktelen költekezés, szexuális kalandok, felelőtlen üzleti befektetések). </string>
<string name="table1_3">A tünetek <b>nem</b> elégítik ki <b>a kevert epizód ismérveit.</b></string>
<string name="table1_4">A hangulatzavar elegendően súlyos ahhoz, hogy: \n \n1. jelentős zavart okozzon a munka vagy a szokásos társas tevékenységek, illetve kapcsolatok terén, vagy \n2. az ön- és közveszélyesség miatt kórházi kezelést tegyen szükségessé, vagy \n3. pszichotikus tünetek fellépjenek.</string>
<string name="table1_5">A tünetek <b>nem</b> tulajdoníthatók valamilyen szer (pl. kábítószer, gyógyszer stb.) közvetlen fiziológiai hatásának, és organikus betegség (pl. hyperthyreosis) kiváltó szerepe sem állapítható meg.</string>
<string name="table1_6"><b>Megjegyzés:</b> Egyértelműen az antidepresszív kezelés (pl. gyógyszer, elektrokonvulzív- vagy fényterápia) által kiváltott mániaszerű epizódok nem sorolhatók a bipoláros I. zavarokhoz.</string>
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
KhalDrogo
  • 315
  • 1
  • 4
  • 8

1 Answers1

2

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.

user
  • 86,916
  • 18
  • 197
  • 190
  • Is there any way to highlight the word(the matches) what i'm looking for. Underline it, or give it different background. I make your first option, i use database. – KhalDrogo Sep 26 '12 at 11:10
  • @KhalDrogo See the `Spannable` class from the SDK, also you might want to look at http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview – user Sep 26 '12 at 11:14