Reputation: 3964
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...
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tiemyComments"
android:text="@={myComments}" />
Upvotes: 3
Views: 253
Reputation: 11
there are 3 ways to fixed
customize your TextInputEditText class
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} />
Upvotes: 1