skip to Main Content

I have an English teaching app where the users are given some sentences with their Turkish equivalents. I retrieve the data from Strings.xml as follows:

<.b>Possession (Aitlik)</b>nnhave
        (sahip olmak)npossess (sahip olmak)nown (sahip olmak)nbelong (ait olmak)nconsist (-den meydana gelmek)nlack (eksik olmak)ninvolve
        (içermek)nn<.b>Emotions (Duygular)</b>nnlike (sevmek)ndislike (sevmemek)nprefer (tercih etmek)nappreciate (takdir etmek)nneed
        (ihtiyacı olmak)nwish (istemek, dilemek)nhope (ummak)nvalue (değer vermek)nadore (hayran olmak)nfear (korkmak)nsurprise (şaşırtmak)nenvy
        (kıskanmak)nhate (nefret etmek)nlove (sevmek)nn
    ...

If the user wishes, I’d like to hide the translations of the words. Is there a way to do it? So far, I tried separating the example sentences from their translations and hiding the translations from the code:

<string name=header_one>"<.b>Possession</b>"</string>
<string name=header_one_translation>"<.b>Aitlik</b>"</string>
binding.hideTranslationsButton.setOnClickListener {
            binding.headerOneTranslation.isGone = true
            binding.translationOne.isGone = true
            binding.translationTwo.isGone = true
            binding.translationThree.isGone = true
            binding.translationFour.isGone = true
            binding.translationFive.isGone = true
            binding.translationSix.isGone = true
            ...
        }

but it took too much time and it feels like my code has gotten messier considering I have 50 other grammar topics like this (I put dots intentionally –> <.b>).

3

Answers


  1. use recycleview and handle hide text in adapter of recycleview

    Login or Signup to reply.
  2. Maybe think about reordering your layouts.
    Dunno what your structure is.

    <LinearLayout id=root>
       <LinearLayout id=english>
           <LinearLayout id=sentence1/>
           <LinearLayout id=sentence2/>
       </LinearLayout>
       <LinearLayout id=turkish>
           <LinearLayout id=translate1/>
           <LinearLayout id=translate2/>
       </LinearLayout>
    </LinearLayout>
    

    and now you hide the turkish layout.

    Login or Signup to reply.
  3. You can use a regex like

    ((.*)) *(.*)
    

    It simply says there is a group (first parenthesis pair – group 1) inside that we expect
    a opening parenthesis (

    then anything except linebreak . with any count * (probably + is even better instead of * so it can skip empty items)

    then we expect a closing parentheses )

    then there might be some spaces which we don’t care about *

    and then another group (group 2) which is whatever with any count .* (again, + seems more suitable)

    So you can use something like

    "((.+)) *(.+)".toRegex().matches(getString(R.string.blah_blah)).forEach{
        val en = it.groups[1]
        val tr = it.groups[2]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search