0

I am facing two problems. 1. Counting multiple phone number from editText field. 2. Counting SMS number after crossing specific number of characters.

<android.support.design.widget.TextInputLayout
                android:id="@+id/phoneContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:counterEnabled="true"
                app:counterMaxLength="50">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/idContacts"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Recipients"
                    android:ems="10"
                    android:inputType="phone"
                    android:padding="15dp" />
</android.support.design.widget.TextInputLayout>

Here,I can count character of phone number.I need to count the whole phone number.Example: If user types 012346771233,02546547589 in phone edit field,it will count as 2. But in my case ,it is counting single character.I searched lot ,but could not find any solutions.

Secondly,I have a editText field where user can input messages.When user crosses specific numbers(as 160 character) of character,it will do 2 actions.It will increase the sms number and also set character numbers(as 146 character) for next sms.

<android.support.design.widget.TextInputLayout
                    android:id="@+id/textContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:counterEnabled="true"
                    app:counterMaxLength="160">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/idMsg"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:ems="10"
                        android:hint="@string/message"
                        android:inputType="text|textMultiLine|textAutoCorrect"
                        android:padding="10dp"
                        whatever:emptyErrorString="Message can not be empty."
                        whatever:testType="alpha" />
</android.support.design.widget.TextInputLayout>

In my case,I can count characters but how can I count sms numbers and set counterMaxLength for next sms?

Avijit
  • 687
  • 2
  • 8
  • 18
  • For 1st one, write an `onchange` listener and obtain the value of `EditText`, split the string by `.`(dot) and find its length. For 2nd one, write an `onChange` listener and obtain the value of the `EditText` and find the string length and have your 160char logic implemented there. – Panther Apr 01 '17 at 06:55
  • Thanks for your quick response.I got your point.Please,check the link [link]https://unsee.cc/domebuga/ Can you please tell me how to set value of red box ? – Avijit Apr 01 '17 at 07:43
  • I hope, its a simple `TextView`, in the first onChange listener obtain its reference using `findViewById` in the code and use `setText` your desired value to it. say for eg `recipients.setText(`2/50`)` – Panther Apr 01 '17 at 07:52
  • thanks...I got the ans... :) – Avijit Apr 01 '17 at 08:26

1 Answers1

0

for your first question you can do your calculation inside EditText onchange listener

yourEditText.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) {

        if (s.length() >= 0) {

            String []phnArray = s.toString().split(",");
            int phCount  = phnArray.length;
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
});

For your second question it is kind of unclear to me what you actually want.

if you want to check if length crosses 160 then you can check

if(s.length > 160){
    //do your require changes here
} 
Kunu
  • 5,078
  • 6
  • 33
  • 61
  • thanks,man.It's working....one thing more ,can you tell me about phone number formatting ? – Avijit Apr 01 '17 at 08:26
  • If it working then you should accept the answer. And for phone number formatting follow [[http://stackoverflow.com/questions/15494093/phone-number-format-in-android](http://stackoverflow.com/questions/15494093/phone-number-format-in-android) – Kunu Apr 01 '17 at 08:45