0

I have an activity that has a single Edit Text and list view below it. I want that when the user makes changes on the edit text, it is saved in the database. I have used the onfocus change method of EditText. But the problem is the EditText is never loosing its focus. I even tried clicking some list view items but no use. I want to save changes in the database, once the user closes the keyboard which is opened when the Edit Text is opened

coderVishal
  • 8,369
  • 3
  • 35
  • 56

1 Answers1

0
public class TesstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    EditText text = (EditText) findViewById(R.id.editText1);
    text.setOnKeyListener(onSoftKeyboardDonePress);

}

private View.OnKeyListener onSoftKeyboardDonePress=new View.OnKeyListener()
{
    public boolean onKey(View v, int keyCode, KeyEvent event)
    {
        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
        {
            Toast.makeText(TesstActivity.this, "checking event", Toast.LENGTH_LONG).show();
        }
        return false;
    }
};

}

  • the keyboard wont close after I press enter key, and do you have anyway if the User Presses the back key – coderVishal May 02 '14 at 09:58
  • There is a funtion called onBackPressed() u should override it.. and check out this thread http://stackoverflow.com/questions/8785023/how-to-close-android-soft-keyboard-programatically to close/open keyboard –  May 02 '14 at 11:09