N
N
Nikolai Zobnin2014-12-17 17:42:33
Java
Nikolai Zobnin, 2014-12-17 17:42:33

How to get data from EditText in custom SimpleCursorAdapter?

Can't get data from EditText in custom SimpleCursorAdapter?

class TratiSimpleCursorAdapter extends SimpleCursorAdapter { 
Context ctx; 
DataBaseHelper db;
 
public TratiSimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { 
    super(context, layout, c, from, to, flags); 
    this.ctx=context; 
} 
 
@SuppressLint("CutPasteId")
@Override 
public void bindView(View view, Context context, Cursor cursor) { 
    db = new DataBaseHelper(null);
    db.openDataBase();
 
    String name = cursor.getString(cursor.getColumnIndex(DataBaseHelper.COLUMN_TRATI_NAME)); 
    int stoimost = cursor.getInt(cursor.getColumnIndex(DataBaseHelper.COLUMN_TRATI_STOIMOST)); 
    TextView formname = (TextView) view.findViewById(R.id.tv_organizer_trati_listitem_name); 
    EditText formstoimost = (EditText) view.findViewById(R.id.et_organizer_trati_listitem_info); 
    int id = cursor.getInt(cursor.getColumnIndex(DataBaseHelper.COLUMN_TRATI_ID));
    formname.setText(name);             
    formstoimost.setText("" + stoimost); 
    
    formstoimost.setOnKeyListener( new View.OnKeyListener() { 
        public  boolean onKey ( View v ,  int keyCode ,  KeyEvent  event )  { 
            if(v != null) {
                Object obj = v.getTag();
                if(obj != null && obj instanceof Integer) {
                    if(event.getAction() == KeyEvent.ACTION_DOWN && 
                            (keyCode == KeyEvent.KEYCODE_ENTER)){
                    // открываем подключение к БД
                    db = new DataBaseHelper(null);
                    db.openDataBase();
                    if (!formstoimost.getText().toString().equals("")){                 {
                    // если есть текст
                        int newStoimost = Integer.parseInt(formstoimost.getText().toString());
                        db.addRecTratiStoimost(((Integer)obj).intValue(), newStoimost);   
                    }
                    }
                        }
                        db.close();
              return true;
            
        } 
            }
            return false;
            }
    });
Object obj = cursor.getInt(cursor.getColumnIndex("_id"));
formstoimost.setTag(obj);
db.close();
} 
}

I do not know how to read the data entered by the user immediately, with their entry into the database.
Swears at any call to formstoimost.getText().toString() inside OnKeyListener.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zildarius, 2015-01-16
@zildarius

And how exactly does it swear? Probably the fact that this is not a final variable?
Try like this:

final EditText formstoimost = (EditText) view.findViewById(R.id.et_organizer_trati_listitem_info);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question