Why does it work

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tx1 = (EditText) findViewById(R.id.editText1); tx2 = (EditText) findViewById(R.id.editText2); tx3 = (EditText) findViewById(R.id.editText3); tx4 = (EditText) findViewById(R.id.editText4); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.editText1: index =1; break; case R.id.editText2: index =2; break; case R.id.editText3: index =3; break; case R.id.editText4: index =4; break; } } @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { switch (index){ case 1: Log.d(TAG, String.valueOf(editable)); break; case 2: Log.d(TAG, String.valueOf(editable)); break; case 3: Log.d(TAG, String.valueOf(editable)); break; case 4: Log.d(TAG, String.valueOf(editable)); break; default: break; } } } 

And it does not work

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View buttonLayout = inflater.inflate(R.layout.fr_application_form, null); final EditText et1=(EditText)buttonLayout.findViewById(R.id.appName); final EditText et2=(EditText)buttonLayout.findViewById(R.id.appLastName); final EditText et3=(EditText)buttonLayout.findViewById(R.id.appEmail); final EditText et4=(EditText)buttonLayout.findViewById(R.id.appPhone); et1.setOnClickListener(this); et2.setOnClickListener(this); et3.setOnClickListener(this); et4.setOnClickListener(this); return buttonLayout; } @Override public void onClick(View v) { switch (v.getId()){ case R.id.appName: mIndexTextEdit=1; Log.d(TAG, String.valueOf(mIndexTextEdit)); break; case R.id.appLastName: mIndexTextEdit=2; Log.d(TAG, String.valueOf(mIndexTextEdit)); break; case R.id.appEmail: mIndexTextEdit=3; Log.d(TAG, String.valueOf(mIndexTextEdit)); break; case R.id.appPhone: mIndexTextEdit=4; Log.d(TAG, String.valueOf(mIndexTextEdit)); break; default: mIndexTextEdit=0; Log.d(TAG, String.valueOf(mIndexTextEdit)); break; } } @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) { switch (mIndexTextEdit){ case 1: mName = s.toString(); Log.d(TAG, mName); break; case 2: mLastName = s.toString(); Log.d(TAG, mLastName); break; case 3: mEmail = s.toString(); Log.d(TAG, mEmail); break; case 4: mPhone = s.toString(); Log.d(TAG, mPhone); break; default: break; } } } 

It is impossible to determine which click EditText

When you click on one of the EditText in the field, it records its index (the fragment does not work), after which the interface for changes in the EditText is implemented at this index (the fragment does not work)

  • What is not working and how it should be completely out of the question is not clear - YuriySPb
  • one
    Maybe you need to add addTextChangedListener(this) for each edittext - Frozik6k
  • @MaksimPonomarev thank you !!! You partially helped me. but the index still does not correctly record the index after the second click, but you need to record it from the first) - user208111

0