我在 android 中创建了一个自定义对话框,其中包含一个 EditText 和一个 ListView。当我选择任何项目时,列表视图 onItemClickListener 会正确触发,但我的 EditText 的侦听器并非如此。
这是我的代码:
EditText filterEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutInflater factory = LayoutInflater.from(this);
View content = factory.inflate(R.layout.dialog_layout, null);
filterEditText = (EditText) content
.findViewById(R.id.filterEditText);
filterEditText.addTextChangedListener(txtListener);
............
TextWatcher txtListener = new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
filterEditText.setText("text entered");
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
};