Buda Gavril
Buda Gavril

Reputation: 21647

android editText is cursor visible?

Is there any way to know if on a edit text is visible or not the cursor? I need to know so I can adapt a delete method. Thanks

Upvotes: 1

Views: 2587

Answers (1)

Caner
Caner

Reputation: 59168

public static final int getSelectionStart (CharSequence text) Since: API Level 1

Return the offset of the selection anchor or cursor, or -1 if there is no selection or cursor.

So if it returns -1 you know there is no cursor.

EDIT:

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            // cursor visible!!!
        }
    }
});

Upvotes: 1

Related Questions