Есть кастомный SimpleCursorAdapter, значения для EditText формируются из базы данных. Так же можно изменять значение и оно сразу заноситься в базу.
Все плывет напрочь при прокручивании ListView. Я так понял нужно формировать ссылки на EditText.
Вот код:
Код: Выделить всё
class TratiSimpleCursorAdapter extends SimpleCursorAdapter {
Context ctx;
DataBaseHelper db;
Cursor cursor;
public TratiSimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
this.ctx=context;
this.cursor=c;
}
@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));
final int id = cursor.getInt(cursor.getColumnIndex(DataBaseHelper.COLUMN_TRATI_ID));
TextView formname = (TextView) view.findViewById(R.id.tv_organizer_trati_listitem_name);
EditText formstoimost = (EditText) view.findViewById(R.id.et_organizer_trati_listitem_info);
formname.setText(name);
formstoimost.setText("" + stoimost);
formstoimost.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (!s.toString().isEmpty() && !s.toString().equals("0")) {
// открываем подключение к БД
db = new DataBaseHelper(null);
db.openDataBase();
db.addRecTratiStoimost(id, Integer.parseInt("" + s));
Log.d(MainActivity.TAG,"Адаптер курсор: " + id + " Новая стоимость " + s);
}
}
@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
}
});
db.close();
}
}
Код: Выделить всё
Object obj = cursor.getInt(cursor.getColumnIndex("_id"));
button.setTag(obj);
button.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View view) {
if(view != null) {
Object obj = view.getTag();
if(obj != null && obj instanceof Integer) {
}
}