Skip to content Skip to sidebar Skip to footer

Android Edittext With Listview Detecting Change

I have a simple listview with a TextView and an Editview that is populated using the SimpleCursorAdapter from a SQLITE query. I am trying to figure out when the user has left the

Solution 1:

The view you are receiving from getView is not inflated into ListView, so your TextWatcher is not working as expected. To make it work you have to create your own adapter. For example

publicclassMySimpleCursorAdapterextendsSimpleCursorAdapter {
    publicMySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
        super(context, layout, c, from, to, flags);
    }

    @Overridepublic View getView(int pos, View v, ViewGroup parent) {
        v = super.getView(pos, v, parent);
        finalEditTextet= (EditText) v.findViewById(R.id.classpercentage);
        et.addTextChangedListener(newTextWatcher() { 
            publicvoidafterTextChanged(Editable s) { Log.d("TEST", "In afterTextChanged"); } 
            publicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) { Log.d("TEST", "In beforeTextChanged"); } 
            publicvoidonTextChanged(CharSequence s, int start, int before, int count) { Log.d("TEST", "In onTextChanged"); } 
        }); 
        return v;
    }
}

and then you method will be modified to this

privatevoidshowClasses(Cursor cursor) {
    SimpleCursorAdapteradapter=newMySimpleCursorAdapter(this, R.layout.classrow, cursor, FROM, TO);
    setListAdapter(adapter);
}

Post a Comment for "Android Edittext With Listview Detecting Change"