2

I am displaying a list from database i want the labels to be bold.

   Cursor cursor = GetAllData();
           StringBuilder stringBuilder =new StringBuilder();
           while(cursor.moveToNext()){
               stringBuilder.append("Id :" + cursor.getString(0)+ " | " +"Name :"+ 
     cursor.getString(1)+" | "+"Address :" + cursor.getString(2)+" | "+"Phone :" + 
      cursor.getString(3)+"\n"+"--------------------------------------------------"+"\n");
           }
           textView.setText(stringBuilder);

That is Id,Name,Address must be bolded what to add to make it bolder.

Ravish
  • 45
  • 1
  • 6
  • https://stackoverflow.com/questions/60631322/set-gradient-color-for-text-in-android-studio-with-kotlin-language – MMG Apr 24 '20 at 16:21

1 Answers1

3

You are setting a textView. Add HTML bold tags. Also, that is terrible code. You are nesting StringBuilder (because String + String uses another StringBuilder). Also, it's a bad idea to assume the line separator is \n. Fixing it should be simple enough. Something like,

Cursor cursor = GetAllData();
StringBuilder sb = new StringBuilder();
while (cursor.moveToNext()) {
    sb.append("<b>Id</b> :").append(cursor.getString(0));
    sb.append(" | <b>Name</b> :").append(cursor.getString(1));
    sb.append(" | <b>Address</b> :").append(cursor.getString(2));
    sb.append(" | Phone :").append(cursor.getString(3));
    sb.append(System.lineSeparator());
    sb.append("--------------------------------------------------");
    sb.append(System.lineSeparator());
}
textView.setText(Html.fromHtml(sb));
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249