Reputation: 6962
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
Upvotes: 6
Views: 15301
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
Reputation: 1
editText.isEnabled = false // makes it`s color grey
editText.setTextColor(Color.parseColor("#DE000000")) //change color if needed
Upvotes: 0
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
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
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
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
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
Reputation: 349
Try with this code
EditText et = (EditText) findViewById(R.id.your_edit_text);
et.setFocusable(false);
et.setClickable(true);
Upvotes: 0
Reputation: 75788
Try with
android:focusable="false"
android:focusableInTouchMode="false"
Upvotes: 8