0

My Code is: These Take the Custom 3 edittext Than how to adddtextChanged listener to particular foucused Edittext. the Last edittext focues if delete remaining two and if blank third

for(int i=0;i<3;i++)
{

LinearLayout.LayoutParams lparams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);


 TextInputLayout input ;
input = new TextInputLayout(this);

input.setLayoutParams(lparams);

 et = new EditText(this);
 et .setLayoutParams(lparams);
  et .setHint(item.getLabel());
   et .setMinLines(1);

  input.addView(et);
 rl_MainLayout1.addView(input);


   et.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

                }

                @Override
                public void afterTextChanged(Editable editable) {


                    if ( et.getText().toString().trim().isEmpty()) {
                        input.setError(getString(R.string.msg_errorName));
                        requestFocus(et);

                    } else {
                        input.setErrorEnabled(false);
                    }
                }
            });
 }
Arjun saini
  • 4,223
  • 3
  • 23
  • 51

2 Answers2

0

Add TextChangedListener to edit text in for loop.

declare global variable named current as

int current = 0;

and change value of that variable on click of EditText

for(int i=0;i<3;i++) {
    final int val = i;
    ..
    ..
    et.addTextChangedListener(new TextWatcher(){

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            current = val;
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });
}

and read this current value where ever you want.

ELITE
  • 5,815
  • 3
  • 19
  • 29
0

/I solved this By flag variable/

/first Declare it/

int flag=1;

/on Loop flag++;/

 if(flag==1)
            {
  et1=new EditText(this);
                 }
 else if(flag==2)
            {
  et2=new EditText(this);

                 }

 flag++;
Arjun saini
  • 4,223
  • 3
  • 23
  • 51