Combining Urdu String through Data Binding

Today, I had a case in my app where there was an EditText and TextView. The goal was that when EditText is changed, then TextView value will be updated instantly. So TextView value will be like this:

    textView = "SOME URDU STRING 1" + editTextValue + "ANOTHER URDU STRING"

First, I added a String value in my strings.xml file which was like this:

        <string name="app_name">AppName</string>
        <string name="sarbarah_str">آپ کا گھر کے سربراہ %s سے کیا رشتہ ہے؟</string>        // My String

Please note the %s in the string. That’s where magic happens. Then in my layout, I had EditText and TextView like this:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android=""

        <import type="com.wajahatkarim3.myapp.R"/>


            android:onTextChanged='@{(text, start, before, count) -> textView.setText(String.format(context.getString(R.string.sarbarah_str, text)))}' />

            app:layout_constraintTop_toBottomOf="@+id/editText" />


So, the main line is:

    android:onTextChanged='@{(text, start, before, count) -> textView.setText(String.format(context.getString(R.string.sarbarah_str, text)))}'

So, whatever text is entered in EditText, that is added in place of %s in the string, and that value is set to the TextView.

And that’s it.

If you liked this article, you can read my new articles below:

Wajahat Karim is Pakistan’s first Google Developer Expert in Android. As an experience Android developer, he deeply cares about it and keeps writing and speaking about it. He has written two worldwide 300+ pages books on Android development with more than 100 articles around the internet either on his website or his Medium publications. He is also a passionate contributor in open source and has created many Android libraries used by thousands of developers in their apps worldwide. As active public speaker, he spends lots of time giving talks in conferences and motivating people on Android development. You can find Wajahat most active on Twitter @WajahatKarim where he regularly shares all the good stuff about Android and community building.

Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan