Я вызываю метод помощника db, когда пользователь нажимает кнопку done/next/enter, но этот код выполняется дважды, а данные дважды вводятся в таблицу.Данные вставляются дважды в ключевое событие пресса edittext в Android
Вот мой ключ пресс событие редактирования текста:
editTextLitre.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch(keyCode){
case KeyEvent.KEYCODE_ENTER:
TextView txtlitres = (TextView)findViewById(R.id.edit_text_litre);
TextView totalamount = (TextView)findViewById(R.id.amount);
RadioButton rbBuffalo = (RadioButton) findViewById(R.id.radioBuffalo);
RadioButton rbCow = (RadioButton) findViewById(R.id.radioCow);
rbBuffalo.setText(Constants.Buffalo.toString());
rbCow.setText(Constants.Cow.toString());
radioanimal= (RadioGroup)findViewById(R.id.radioCategory);
int selectedid = radioanimal.getCheckedRadioButtonId();
rb = (RadioButton)findViewById(selectedid);
DBHelper dh=new DBHelper(getApplicationContext());
// TODO Auto-generated method stub
boolean save = dh.insertMilkDetails(mandali,rb.getText().toString(),totalamount.getText().toString(),txtlitres.getText().toString(),dt.toString(),session.toString());
if(save == true)
{
Toast.makeText(getApplicationContext(), "Details Saved Successfully", Toast.LENGTH_SHORT).show();
}
return false;
}
});
Я не могу понять, почему данные вставляются дважды в таблице базы данных.
Опубликовать еще код. – GrIsHu