After each comma restrict to six characters in android
<p>i need to restrict six characters after comma in edittext of android and i should able to add characters bfor comma...</p>

<p>ie 3000,898989,898345...3000 can be 30000 or 300000...infinite but characters after comma should be fixed to six... </p>

<p>after each comma only six character canbe typed in edit text...</p>

<p>how to go about it?</p>

<p>i have tried with the following</p>

<pre><code>public class CustomEditTextActivity extends Activity {

EditText et;
Context cn=null;
int commacount=0;
String aftercomma;
boolean  flag=false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
                             cn=this;
    et=(EditText)findViewById(R.id.editText1);

    // Listener for edit text text change
    et.addTextChangedListener(filterTextWatcher);


}

private TextWatcher filterTextWatcher = new TextWatcher() {

    public void afterTextChanged(Editable arg0) {
        // TODO Auto-generated method stub

        System.out.println("Inside afterTextChanged() method");



    }

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

        System.out.println("Inside beforeTextChanged() method");


    }

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
                      flag=false;
        commacount=0;
        String getDataFromeditxt = s.toString();
                int comma = getDataFromeditxt.indexOf(',');
                String bforcomma = getDataFromeditxt;
                if (comma != -1)
                {
                    bforcomma = getDataFromeditxt.substring(0, comma);
                }



                               // Checking for , in the data and setting its position
                                for (int i = 0; i &lt; getDataFromeditxt.length(); i++) {
                                    char c = getDataFromeditxt.charAt(i);
                                     if(flag){
                                      aftercomma=new StringBuilder().append(c).toString();
                                         int maxLength =bforcomma.length() +6+commacount;
                                        InputFilter[] FilterArray = new InputFilter[1];
                                        FilterArray[0] = new InputFilter.LengthFilter(maxLength);
                                        et.setFilters(FilterArray);
                                        System.out.println(aftercomma);

                                    }
                                    if (c == ',') {
                                        commacount=commacount+1 ;
                                         flag=true;
                                    }

                                }

    }

};
</code></pre>

<p>}</p>

<p>the problem in above code is that once maxlength is set i can't type anyting...any solution??</p>
