How can I change the color or make part of a large text array bold in Kotlin?

19 Views Asked by At

Help solve the problem. If you use string resources, then you can change part of the text to a different color or make it bold using text or text. Here I am trying to do the same in the array resources, I have a very large text there. But what works in string resources doesn't work in an array. Please help me solve this issue.

textView.setText(resources.getTextArray(R.array.sedob_grib_content) it doesn't work that way

array file `

<string-array name="text_content ">

    <item><d>text text text text</d>, texttexttext</item>
    <item><font color='color'>text text text text</font>, texttexttext</item>
    <item>text text text text, texttexttext</item>
    <item>text text text text, texttexttext</item>
    <item>text text text text, texttexttext</item>

</string-array>

`

fragment file

`private lateinit var binding: FragmentBinding

private val ViewModel: SedViewModel by activityViewModels()

var adapter: SedAdapter? = null
var list = ArrayList<ListItem>()


override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    binding = FragmentBinding.inflate(layoutInflater)
    return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    list.addAll(fillArrays(resources.getStryngArray(R.array.text_content)))
    rcView.hasFixedSize()
    rcView.layoutManager = LinearLayoutManager(requireActivity())
    adapter = SedAdapter(list)
    adapter!!.stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY
    rcView. adapter = adapter

    adapter?.setOnItemClickListener(object : SedAdapter.onItemClickListener{
        override fun onItemClick(position: Int) {
            ViewModel.setSelected(list[position])
            parentFragmentManager.beginTransaction()
                .replace(R.id.dataContainer, ContentFragment())
                .addToBackStack(null)
                .commit()
        }
    })
}

private fun fillArrays(titleArray:Array<String>):List<ListItem>{
    val listItemArray = ArrayList<ListItem>()
    for (n in titleArray.indices){
        val listItem = ListItem(titleArray[n])
        listItemArray.add(listItem)
    }
    return listItemArray
}

`

0

There are 0 best solutions below