Answer the question
In order to leave comments, you need to log in
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();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question