Android EditText and addTextChangedListener
im currently porting a database manager to android and due to performance reasons i like to update only propertys that have been modified. Im trying to do this with the addTextChangedListener in order to add modified entrys to a List, but my Program never enters any of its methods.
EditText Et = (EditText) Editors.get(Prop.Name);
Et.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if(Prop.GetType() == Property.PROPTYPE.num) {
float f = Float.parseFloat(s.toString());
Prop.FromString(f);
}
else {
Prop.FromString(s.toString());
}
propertiesToUpdate.add(Prop);
});
Et.setText(Prop.ToString());
Why are getting the EditText instance this way. It's part of your activity layout so you should get it something like this
EditText Et = (EditText) findViewById(R.id.your_id);
I think the problem is that you're holding a reference to a EditText which don't belong to your Activity layout so you are attaching the listener to the wrong view.
链接地址: http://www.djcxy.com/p/50930.html