Я пытался просмотреть модель в android, поэтому для MainViewModel. java Я написал это:
public class MainViewModel extends ViewModel {
private String textView;
private String editText;
//@Bindable
public String getTextView(){
return textView;
}
private void setTextView(String value){
textView=value;
}
//@Bindable
public TextWatcher getEditTextWatcher() {
return new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
setTextView(s.toString());
}
...
};
}
}
И в ActivityMain. xml Я написал это:
<TextView
android:text="View-Model / Data-Binding"
android:layout_width="match_parent"
android:layout_height="40dp"/>
<TextView
android:id="@+id/main_text_view"
android:text="@{mainvm.textView}"
android:layout_width="match_parent"
android:layout_height="40dp"/>
<EditText
android:id="@+id/main_edit_text"
app:textChangeListener="@{mainvm.editTextWatcher}"
android:layout_width="match_parent"
android:layout_height="40dp"/>
Я получаю 2 ошибки:
Cannot find a setter for <android.widget.EditText app:textChangeListener> that accepts parameter type 'android.text.TextWatcher'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
И,
error: cannot find symbol class ActivityMainBindingImpl
В некоторых статьях используется аннотация @Binable, расширяющая BaseObservable, что не является предметом ViewModel.
Итак, мой вопрос, как я могу решить это?