'Two way data binding issue of \n (new line) while set String into Edittext

I am facing one issue while set data into Edittext when using TWO WAY DATA BINDING which contain HTML tags like " < br > " or \n.

when there is \n it next data should be in new line.

it shows me like...

enter image description here

 <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/tiemyComments"
                        android:text="@={myComments}" />


Solution 1:[1]

there are 3 ways to fixed

  1. customize your TextInputEditText class

  2. do one method inside you data class and set logic inside that method ex user class username contains html text so i will do one method like convert htmltoText method and do logic inside that method and return string

public class DataBindingAdapter {
    @BindingAdapter("convertHtmltoText")
    public static void convertHtmltoText(TextInputEditText view, String value) {

        string description = value.replace("\n", "<br/>") ?: ""
        view.setText(HtmlCompl?at.fromHtml(description, 
 HtmlCompat.FROM_HTML_MODE_LEGACY));

    }
}

<com.google.android.material.textfield.TextInputEditText
 android:id="@+id/tiemyComments"
 convertHtmltoText="@{myComments} />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suraj Rao