3

when i have only few edit texts using textchangeListener or compare texts to find the text is changed or not if i have more than 20 edittext how to know the edit text is changed or not

i found nearly same asked here 1. How to check if an EditText was changed or not? 2. Knowing when Edit text is done being edited this is helpful ...There is any simple way to do this.

String temp = "aa";
    if(temp.equals(edittext.getText().toString()) {
        Log.e("Not Change",temp);
    } else {
            Log.e("Changed Value",edittext.getText().toString());
    }

Thanks in advance...

Community
  • 1
  • 1
Vini
  • 967
  • 1
  • 15
  • 33

2 Answers2

2

Try something like below:

EDIT:

n1I1 = (EditText) findViewById(R.id.etN1I1);
n1I2 = (EditText) findViewById(R.id.etN1I2);
n1I3 = (EditText) findViewById(R.id.etN1I3);


 TextWatcher textWatcher = new TextWatcher() {

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 Toast.makeText(yourActivity.this,"changed",0).show();
    }

    @Override
    public void afterTextChanged(Editable editable) {

    }
};

ArrayList<EditText> firstList = new ArrayList<EditText>();
firstList.add(n1I1);
firstList.add(n1I2);
firstList.add(n1I3);

for(int i=0;i<firstList.size();i++)
{
 firstList.get(i).addTextChangedListener(textWatcher);
}
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
  • the temp value i provide for sample ...i want to compare the new edit text value with previous value... – Vini Dec 07 '13 at 11:24
  • it doesnt show the changed toast...that is when delete the old records and insert new records then only the toast shown – Vini Dec 07 '13 at 12:06
2

please make a common method for all Edittext like this:

private void checkEditText(String temp, EditText edittext){
 if(temp.equals(edittext.getText().toString()) {
     Log.e("Not Change",temp);
 } else {
     Log.e("Changed Value",edittext.getText().toString());
 }

}

use a switch case for calling this method for individual Edittext.

Let me know if u get any problem.

Karan Maru
  • 991
  • 6
  • 17