1

Orignal Question

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onValueChange="@{handler.passwordValidator}"
    android:text="@={model.password}"/>

I could not find parameters of android:onValueChange. What should I put in below method parameters?

public void passwordValidator() {

}
  • I tried to pass empty method to this attribute, thought that logs will tell me its arguments, but I could not get that.

  • I could not find it in EditText Documentation.

  • Google search results does not contain any information about this.

Tried many possible parameters cases

android:onValueChange="@{handler.passwordValidator}"

android:onValueChange="@{handler::passwordValidator}"

android:onValueChange="@{()->handler.passwordValidator()}"

android:onValueChange="@{(v)->handler.passwordValidator()}"

android:onValueChange="@{(view, value) ->handler.passwordValidator()}"

Also please tell a way to find parameters of any attribute, so that I can find myself.

Please note, It is not related to android:onTextChanged.

Update 1

@Tenten I got this in suggestions.

suggestion

Update 2 (I thinnk, It is not IDE bug)

It can not be bug of Android because when you put unknown attribute then error comes after compilation.

Case 1 (unknown attribute)

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:asdf=""
    android:text="@={model.password}"/>

AGPBI: {"kind":"error","text":"error: attribute \u0027android:asdf\u0027 not found.","sources":[{"file":"E:\AndroidWorkspace\RawSamples\Sample\app\src\main\res\layout\activity_main.xml","position":{"startLine":23}}],"original":"","tool":"AAPT"}

Case 2 (using android:onValueChange)

Error is changed in this case, if there is no android:onValueChange attribute then error should be same.

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onValueChange="@{handler::passwordValidator}"
    android:text="@={model.password}"/>
  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

    android.databinding.tool.util.LoggedErrorException: Found data binding errors. ****/ data binding error ****msg:Could not resolve handler::passwordValidator as a listener.
    file:E:\AndroidWorkspace\RawSamples\Sample\app\src\main\res\layout\activity_main.xml loc:23:37 - 23:62 ****\ data binding error ****

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • https://stackoverflow.com/questions/33798426/how-to-databind-to-ontextchanged-for-an-edittext-on-android – AskNilesh Sep 18 '18 at 06:19
  • @NileshRathod Hi ,I could not see `onValueChange` in this question. – Khemraj Sharma Sep 18 '18 at 06:20
  • 1
    Where did you get the attribute onValueChange? It seems that there's no onValueChange method on EditText. – Tenten Ponce Sep 18 '18 at 06:25
  • 1
    @Khemraj hm, but also you can see from the screenshot that there's no documentation for it, maybe just a bug of android studio. What are you trying to do? Maybe you can use onTextChanged if you want to get the text. – Tenten Ponce Sep 18 '18 at 06:29
  • 1
    It's IDE's issue, that show you one of properties of android name space, take it easy – Mahdi Rajabi Sep 18 '18 at 06:32
  • @TentenPonce See update part of question. – Khemraj Sharma Sep 18 '18 at 06:40
  • 1
    @TentenPonce there is no documentation of `android:onTextChanged` too. you can check it. Press ctrl + Q in `onTextChanged` block. – Khemraj Sharma Sep 18 '18 at 06:41
  • Hm, its weird, I've also checked up to the `TextView` which is extended by the `EditText` but there's no `onValueChange` too... – Tenten Ponce Sep 18 '18 at 06:51
  • 1
    @TentenPonce This is stupid question. This attribute is related to NumberPicker. I am deleting this question. https://developer.android.com/reference/android/widget/NumberPicker.OnValueChangeListener, Sorry to take your time :D, this is really an IDE issue, that It can not filter attributes related to only EditText. – Khemraj Sharma Sep 18 '18 at 06:53
  • @TentenPonce It says `You can not delete this question, as others have invested time`, it respects your all time. :D, no worries my profile will have 1 stupid question as well. – Khemraj Sharma Sep 18 '18 at 06:55
  • 1
    Ahahaha, that's why I do have trust issues on android studio on XML part :DD – Tenten Ponce Sep 18 '18 at 06:58

2 Answers2

0

replace :

"@{handler.passwordValidator()}"

with

"@{handler::passwordValidator}"

also make following method non-static

public void passwordValidator(View view) {

}
Mahdi Rajabi
  • 582
  • 1
  • 4
  • 11
0

Use this

EditText myTextBox = (EditText) findViewById(R.id.myTextBox);
myTextBox.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start, 
  int count, int after) {
}

public void onTextChanged(CharSequence s, int start, 
  int before, int count) {
    passwordValidator(s.toString());
 }
});

And this

public void passwordValidator(String password) {

}
  • It can be an alternative, but my question was for `onValueChange`, Also I will prefer `android:onTextChange` instead of your solution. – Khemraj Sharma Sep 18 '18 at 06:48