79307996

Date: 2024-12-25 16:39:52
Score: 3
Natty:
Report link

here is the attempt with Spannable, text does not change???

fun getAllMeds(): List<Medication> {
        val medList = mutableListOf<Medication>()
        val db = readableDatabase
        val query = "SELECT * FROM $TABLE_NAME"
        val cursor = db.rawQuery(query, null)

        while (cursor.moveToNext()) {
            val id = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_ID))
            val medpill = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MEDPILL))
            val medtaken = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MEDTAKEN))

            val spannable = SpannableString("Take (" + medpill + ") pill every " + medtaken)
            spannable.setSpan(
                ForegroundColorSpan(Color.RED),
                6, // start
                9, // end
                Spannable.SPAN_EXCLUSIVE_INCLUSIVE
            )
            var newText = spannable.toString()

        val med = Medication(id, newText)
            medList.add(med)

        }
        cursor.close()
        db.close()
        return medList
    }
Reasons:
  • Blacklisted phrase (1): ???
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Robert