Adam Katz
Adam Katz

Reputation: 6962

How to make an Edittext not clickable

I want to make an Editext only focus when I programmably tell it to and not allow the user to press on the one he wants. Is this possible?

I tried

android:longClickable="false"
android:clickable="false"

But neither worked.

For some reason people are thinking the following solves my problem, but that person is trying to make an edit text not editable, where I am trying to make an edit text only not focusable by clicking

EditText not editable

Upvotes: 6

Views: 15301

Answers (9)

Noah Mohamed
Noah Mohamed

Reputation: 134

may be you need to use this line

        android:inputType="none"

in your xml this line will prevent keyboard from showing

Upvotes: 0

Noldor
Noldor

Reputation: 1

editText.isEnabled = false // makes it`s color grey
editText.setTextColor(Color.parseColor("#DE000000")) //change color if needed

Upvotes: 0

jmckie
jmckie

Reputation: 259

I ran into the same issue and solved it by using:

.setEnabled(false) and .setClickable(false)

so use this for your code:

.setEnabled(false);
.setClickable(false);

Upvotes: 5

Alex Cuadrón
Alex Cuadrón

Reputation: 688

PROGRAMATICALLY

I ran into the same issue and solved it by using:

.setEnabled(false), .setClickable(false) and .setFocuseable(false)

so use this for your code:

et.setEnabled(false);
et.setClickable(false);
et.setFocuseable(false);

USING XML

android:focusable="false"

Upvotes: 1

PGMacDesign
PGMacDesign

Reputation: 6302

Not sure if you ever got this answered, but I had to do the same thing and although this may not be concise, I know it works:

First set the keyListener to null:

myEditText.setKeyListener(null);

Next set an OnTouch listener to the EditText to do whatever action you want:

myEditText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if(motionEvent.getAction() == MotionEvent.ACTION_UP){
                    //Do whatever action you need to do here. 
                }
                return false;
            }
});

From there, you can simply insert your actions into the OnTouch listener ACTION_UP action tag. In my case, I needed to popup a Dialog with a listview for them to choose something and then set the respective text into the EditText.

Hope that helps.

Upvotes: 1

AAP
AAP

Reputation: 179

Immediate parent of the EditText should steal the focus.For example:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="enter.." />
</LinearLayout>

Upvotes: 0

AshAR
AshAR

Reputation: 228

In the xml file try using the following code-

    android:clickable="false"
    android:focusableInTouchMode="true"

use it on the EditText. I haven't tried it but hope it works.

Upvotes: -1

Navas pk
Navas pk

Reputation: 349

Try with this code

EditText et = (EditText) findViewById(R.id.your_edit_text);
et.setFocusable(false);
et.setClickable(true);

Upvotes: 0

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Try with

    android:focusable="false"
    android:focusableInTouchMode="false"

Upvotes: 8

Related Questions