Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect touch on EditText, but not interrupt it?

Tags:

android

I need to know when the user touches/taps/clicks the edittext in my activity.

How can I do this without interrupting the events, so the keypad still displays properly?

(And I need to know about it before the OS displays the keypad...if possible)

like image 718
just_another_coder Avatar asked Aug 02 '10 15:08

just_another_coder


People also ask

How do I hide the soft keyboard on Android after clicking outside Edittext?

This example demonstrates how do I hide soft keyboard on android after clicking outside edittext. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I know if Edittext has focus?

You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts.

How do you make Edittext read only?

The most reliable way to do this is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code.


1 Answers

txtEdit.setOnTouchListener(new View.OnTouchListener(){
    public boolean onTouch(View view, MotionEvent motionEvent) {                                                       
         // your code here....
         getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);                
         return false;
    }
});
like image 122
Mathias Conradt Avatar answered Sep 30 '22 03:09

Mathias Conradt