Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText and addTextChangedListener

Tags:

android

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());
like image 298
Alex Avatar asked Feb 21 '11 10:02

Alex


1 Answers

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.

like image 145
Mojo Risin Avatar answered Nov 15 '22 08:11

Mojo Risin