Example EditText Box Input Cleanup Tool Class for Android Development

  • 2021-08-17 00:56:53
  • OfStack

This article illustrates the EditText box input cleanup tool class developed by Android. Share it for your reference, as follows:

This tool class is mainly used to clean the input box. Of course, some will depend on the situation


package com.maobang.imsdk.util;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
/**
 *  Mainly used for edittext Cleanup of box input information 
 * Created by Administrator on 2015/12/18.
 */
public class ClearEditTextUtil {
  /**
   * edittext Enter listening changes in the box clear Icons 
   */
  public static void editTextInputOnListener(final ImageView clearIcon, EditText editText) {
    clearIcon.setVisibility(View.GONE);
    editText.addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
      }
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {
      }
      @Override
      public void afterTextChanged(Editable s) {
        if (s.length() == 0) {
          clearIcon.setVisibility(View.GONE);
        } else {
          clearIcon.setVisibility(View.VISIBLE);
        }
      }
    });
  }
  /**
   *  Clear edittext Information in 
   */
  public static void clearAccountInfo( ImageView clearIcon,EditText editText) {
    // Click the button to delete the text 
    editText.setText("");
    clearIcon.setVisibility(View.GONE);
  }
}

For more readers interested in Android related content, please check the topics of this site: "Android View View Skills Summary", "Android Layout layout Skills Summary", "Android Graphics and Image Processing Skills Summary", "Android Development Introduction and Advanced Tutorial", "Android Debugging Skills and Common Problem Solutions Summary", "Android Multimedia Operation Skills Summary (Audio, Video, Recording, etc.)", "Android Basic Component Usage Summary" and "Android Control Usage Summary"

I hope this article is helpful to everyone's Android programming.


Related articles: