Tarek Zoubi
Tarek Zoubi

Reputation: 53

Setting onClickListener to editText

Hi im trying to add on click listener to editText so i can disable the softkeyboard when user clicks on edittext using this code below, how to do that?

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

Upvotes: 1

Views: 8715

Answers (3)

Daniel
Daniel

Reputation: 1

The easiest and straight forward way you can set it is by editing the xml file as follows:

android:onClick="onClickMyEditText"

and define the same method in Activity class:

public void onClickMyEditText(View view) {
        //your code here
    }

Upvotes: 0

Farshid roohi
Farshid roohi

Reputation: 768

try it and set OnClickListener

  <androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/edt"
            android:inputType="none"
            android:focusable="false"
            android:editable="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

Upvotes: 0

ahdgfd
ahdgfd

Reputation: 325

First it needs to be focusable...

<EditText
    ...
    android:inputType="none"
    android:focusable="false"
    ... />

You have to implement it in your code and than just add this to get an click listener...

myEditText.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // hide the keyboard
        // show own keyboard or buttons
    }
});

Upvotes: 8

Related Questions