Вопрос

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

Это было полезно?

Решение

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;
    }
};

}

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top