Event for Handling the Focus of the EditText

Sheetal Shelar picture Sheetal Shelar · Sep 13, 2011 · Viewed 166.3k times · Source

Can anyone suggest me any event related to the focus of the EditText? My application contains a EditText, which accepts a URL in it.

Now my problem is that, that after the user will enter the URL in the field and Move further, without any of the click event, i.e when the focus will move from the EditText, it should detect the entered Url and goes to the server.

If I get the reply using Json Parsing, then it'll be more convenient.

Answer

Pratik picture Pratik · Sep 13, 2011

Here is the focus listener example.

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (hasFocus) {
            Toast.makeText(getApplicationContext(), "Got the focus", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), "Lost the focus", Toast.LENGTH_LONG).show();
        }
    }
});