Как проверить, какой слушатель editext textwatcher вызывается в динамически созданном edittext
Я могу добавить прослушиватель Textwatcher для динамически создаваемого Edittext, поэтому в основном я проверю первый editext ontexttered, если есть какое-либо значение, создайте другой edittext и т. Д. Как можно проверить, какой edittext вызывается в слушателе.
Я проверил пару ссылоккак в использовании однозначных textwatcher-для-множественного edittexts но идентификаторы являются фиксированными в этом случае.
Код:
public class MainActivity extends Activity {
EditText textIn;
Button buttonAdd;
LinearLayout container;
Button buttonShowAll;
static int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
container = (LinearLayout) findViewById(R.id.container);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
final EditText textOut = (EditText) addView.findViewById(R.id.textout);
textOut.addTextChangedListener(watcher);
container.addView(addView);
}
TextWatcher watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// addView();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
/*
* int childcount = container.getChildCount(); for (int i=0; i <
* childcount; i++){ View v = container.getChildAt(i);
*
* if(i == (childcount -1)){ Toast.makeText(getApplicationContext(),
* "Last count"+childcount, Toast.LENGTH_SHORT).show(); addView(); }
* }
*/
}
};
public void addView() {
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
final EditText textOut = (EditText) addView.findViewById(R.id.textout);
textOut.addTextChangedListener(watcher);
addView.setTag(count++);
container.addView(addView);
}
}