3

I do not want to setText("") to clear the text. I want to simulator the click action of right cross icon. How to do it?

red23jordan
  • 2,841
  • 10
  • 41
  • 57

4 Answers4

3

Based on the implementation of that icon, call setText(null) on the TextInputEditText.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Use:

if (editText != null) {

    editText.getText().clear();
}
RafaelB13
  • 142
  • 2
  • 14
0

( Using Kotlin )

[your ID right cross icon].setOnClickListener {
   [your ID edit text].text.clear()
}
0
(AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment).setText(null)

Ref: https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/widget/AutocompleteSupportFragment#public-autocompletesupportfragment-settext-charsequence-text

It will do exactly what the clear icon does.

red23jordan
  • 2,841
  • 10
  • 41
  • 57