Android EditText with ListView Change List

I have a simple list with TextView and Editview that is populated using the SimpleCursorAdapter from an SQLITE query. I am trying to figure out when the user left EditView so that I can perform some simple validation and update the database. I tried several methods suggested in other posts to do this, but I can not catch the event. Below are two different ways I tried to do this. Please help. I would be very grateful.

    private void showClasses(Cursor cursor) {


    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.classrow, cursor, FROM, TO);

    setListAdapter(adapter);
    adapter.notifyDataSetChanged(); 

                //ATTEMPT 1     
    for (int i = 0; i < adapter.getCount(); i++){
        EditText et = (EditText) adapter.getView(i, null, null).findViewById(R.id.classpercentage);


        et.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub
            Log.d("TEST","In onFocusChange");

        }
    }); 

        //METHOD 2  
         et.addTextChangedListener(new TextWatcher(){ 
        public void afterTextChanged(Editable s) { 
            Log.d("TEST","In afterTextChanged");

        } 
        public void beforeTextChanged(CharSequence s, int start, int count, int after){Log.d("TEST","In beforeTextChanged");} 
        public void onTextChanged(CharSequence s, int start, int before, int count){Log.d("TEST","In onTextChanged");} 
    }); 



    }
}

I don’t see anything in LogCat, and my breakpoints in the debugger do not fall.

0
source share
1 answer

, getView, ListView, TextWatcher , . , .

public class MySimpleCursorAdapter extends SimpleCursorAdapter {
    public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
        super(context, layout, c, from, to, flags);
    }

    @Override
    public View getView(int pos, View v, ViewGroup parent) {
        v = super.getView(pos, v, parent);
        final EditText et = (EditText) v.findViewById(R.id.classpercentage);
        et.addTextChangedListener(new TextWatcher() { 
            public void afterTextChanged(Editable s) { Log.d("TEST", "In afterTextChanged"); } 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { Log.d("TEST", "In beforeTextChanged"); } 
            public void onTextChanged(CharSequence s, int start, int before, int count) { Log.d("TEST", "In onTextChanged"); } 
        }); 
        return v;
    }
}

private void showClasses(Cursor cursor) {
    SimpleCursorAdapter adapter = new MySimpleCursorAdapter(this, R.layout.classrow, cursor, FROM, TO);
    setListAdapter(adapter);
}
0

All Articles