1

I need to know how I can get the condition in the onclick, my edittext is a singleline and I want to know when the text is exceeded, for example my edittext has 6 characters "HOLAHI" I add a new character and this show "HOL...".

I want to know until to set the 7th character to change the size font.

ebing
  • 59
  • 1
  • 6

2 Answers2

1

Look here: How to adjust text font size to fit textview

Overview:

  • Create a CustomTextView
  • Extend TextView
  • override method onMeasure()
  • Do your calculations on the text width [Hint: get width by calling this.getWidth()]
  • Set calculated text size [Hint: use this.setTextSize()]
Community
  • 1
  • 1
Abhishek
  • 2,959
  • 2
  • 17
  • 24
0

You can check the content of your EditText should ellipsize by the method provided in TextUtils, the following code is a simple example.

    EditText editText = new EditText(this);
    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) {
            String ellipseString = TextUtils.ellipsize(s, editText.getPaint(), editText.getWidth(), TextUtils.TruncateAt.END, false, new TextUtils.EllipsizeCallback() {
                @Override
                public void ellipsized(int start, int end) {
                }
            }).toString();
            if (ellipseString.contains("\u2026")) {
                Log.d(TAG, "ellipse");
            }
        }
    });
alijandro
  • 11,627
  • 2
  • 58
  • 74