I am trying to make a simple two-way data binding behavior. So I have an edit text in my layout and when the value is changed, I want to update the variable inside my activity.
Here is the code inside my activity:
class MainActivity : AppCompatActivity() {
private var input: String = ""
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.input = input
}
}
Here is my edit text:
<data>
<variable
name="input"
type="String" />
</data>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input number.."
android:inputType="number"
android:text="@={input}" />
But I received an error saying:
Cannot find a setter for <android.widget.EditText android:textAttrChanged> that accepts parameter type 'androidx.databinding.InverseBindingListener' I have tried to make store the input variable as an observable variable of an object class that extends base observable.