How to enable editText on touch
I have an editText which is disabled and I want to enable it when I touch it.
Here is what I've done but it doesn't work :
if(textmail.isEnabled() == false){
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setEnabled(true);
return true;
}
});
}
java android android-edittext
|
show 7 more comments
I have an editText which is disabled and I want to enable it when I touch it.
Here is what I've done but it doesn't work :
if(textmail.isEnabled() == false){
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setEnabled(true);
return true;
}
});
}
java android android-edittext
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
1
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
3
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38
|
show 7 more comments
I have an editText which is disabled and I want to enable it when I touch it.
Here is what I've done but it doesn't work :
if(textmail.isEnabled() == false){
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setEnabled(true);
return true;
}
});
}
java android android-edittext
I have an editText which is disabled and I want to enable it when I touch it.
Here is what I've done but it doesn't work :
if(textmail.isEnabled() == false){
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setEnabled(true);
return true;
}
});
}
java android android-edittext
java android android-edittext
edited Dec 31 '18 at 13:59
Gregor Ažbe
15527
15527
asked Dec 31 '18 at 9:28
user10524436
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
1
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
3
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38
|
show 7 more comments
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
1
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
3
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
1
1
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
3
3
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38
|
show 7 more comments
3 Answers
3
active
oldest
votes
If you disable the Edittext, it will not trigger the events i.e. onTouch/onClick. In order to tackle this issue, you need to avoid using disable and use clickable instead. textmail.setClickable(false);
within your onCreate method.
To make the component look like it has been disabled, you can also work with the Alpha value where you are to reduce the opacity of the component to make it look faded away.
textmail.setAlpha(0.5f);
Now it should response to your listener...
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setClickable(true);
textmail.setAlpha(1f);
return false;
}
});
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
add a comment |
i read your use-case carefully you want to disable your TextView and want to disable it onTouch() (Correct me if i am wrong)
Here's a solution instead of using setEnabled()
as if you set it onTouch()
is not called so better to do it manually by declaring a global variable(boolean) in your (View/activity/fragment/class) where you are writing the logic.
//this as global variable
private boolean isTextViewDisabled=false;
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
return false;
}
}
return true;
}
});
Set your isTextViewDisabled to true
and false
when needed as per your use-case.
But confusion here is condition for enabling and disabling should be something else not the touch event
as according to your use case code should be like below:
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
isTextViewDisabled=false;
}
}
return true;
}
});
The above code doesn't make a lot of sense until you explain why you want to disable the textView
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
add a comment |
try this i hope this help
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(textmail.isEnabled() == false){
textmail.setEnabled(true);
}
return true;
}
});
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985776%2fhow-to-enable-edittext-on-touch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you disable the Edittext, it will not trigger the events i.e. onTouch/onClick. In order to tackle this issue, you need to avoid using disable and use clickable instead. textmail.setClickable(false);
within your onCreate method.
To make the component look like it has been disabled, you can also work with the Alpha value where you are to reduce the opacity of the component to make it look faded away.
textmail.setAlpha(0.5f);
Now it should response to your listener...
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setClickable(true);
textmail.setAlpha(1f);
return false;
}
});
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
add a comment |
If you disable the Edittext, it will not trigger the events i.e. onTouch/onClick. In order to tackle this issue, you need to avoid using disable and use clickable instead. textmail.setClickable(false);
within your onCreate method.
To make the component look like it has been disabled, you can also work with the Alpha value where you are to reduce the opacity of the component to make it look faded away.
textmail.setAlpha(0.5f);
Now it should response to your listener...
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setClickable(true);
textmail.setAlpha(1f);
return false;
}
});
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
add a comment |
If you disable the Edittext, it will not trigger the events i.e. onTouch/onClick. In order to tackle this issue, you need to avoid using disable and use clickable instead. textmail.setClickable(false);
within your onCreate method.
To make the component look like it has been disabled, you can also work with the Alpha value where you are to reduce the opacity of the component to make it look faded away.
textmail.setAlpha(0.5f);
Now it should response to your listener...
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setClickable(true);
textmail.setAlpha(1f);
return false;
}
});
If you disable the Edittext, it will not trigger the events i.e. onTouch/onClick. In order to tackle this issue, you need to avoid using disable and use clickable instead. textmail.setClickable(false);
within your onCreate method.
To make the component look like it has been disabled, you can also work with the Alpha value where you are to reduce the opacity of the component to make it look faded away.
textmail.setAlpha(0.5f);
Now it should response to your listener...
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textmail.setClickable(true);
textmail.setAlpha(1f);
return false;
}
});
answered Dec 31 '18 at 10:27
NeroNero
6991419
6991419
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
add a comment |
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
it worked thank you
– user10524436
Dec 31 '18 at 10:51
it worked thank you
– user10524436
Dec 31 '18 at 10:51
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
@Amal glad I could help :)
– Nero
Dec 31 '18 at 10:52
add a comment |
i read your use-case carefully you want to disable your TextView and want to disable it onTouch() (Correct me if i am wrong)
Here's a solution instead of using setEnabled()
as if you set it onTouch()
is not called so better to do it manually by declaring a global variable(boolean) in your (View/activity/fragment/class) where you are writing the logic.
//this as global variable
private boolean isTextViewDisabled=false;
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
return false;
}
}
return true;
}
});
Set your isTextViewDisabled to true
and false
when needed as per your use-case.
But confusion here is condition for enabling and disabling should be something else not the touch event
as according to your use case code should be like below:
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
isTextViewDisabled=false;
}
}
return true;
}
});
The above code doesn't make a lot of sense until you explain why you want to disable the textView
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
add a comment |
i read your use-case carefully you want to disable your TextView and want to disable it onTouch() (Correct me if i am wrong)
Here's a solution instead of using setEnabled()
as if you set it onTouch()
is not called so better to do it manually by declaring a global variable(boolean) in your (View/activity/fragment/class) where you are writing the logic.
//this as global variable
private boolean isTextViewDisabled=false;
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
return false;
}
}
return true;
}
});
Set your isTextViewDisabled to true
and false
when needed as per your use-case.
But confusion here is condition for enabling and disabling should be something else not the touch event
as according to your use case code should be like below:
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
isTextViewDisabled=false;
}
}
return true;
}
});
The above code doesn't make a lot of sense until you explain why you want to disable the textView
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
add a comment |
i read your use-case carefully you want to disable your TextView and want to disable it onTouch() (Correct me if i am wrong)
Here's a solution instead of using setEnabled()
as if you set it onTouch()
is not called so better to do it manually by declaring a global variable(boolean) in your (View/activity/fragment/class) where you are writing the logic.
//this as global variable
private boolean isTextViewDisabled=false;
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
return false;
}
}
return true;
}
});
Set your isTextViewDisabled to true
and false
when needed as per your use-case.
But confusion here is condition for enabling and disabling should be something else not the touch event
as according to your use case code should be like below:
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
isTextViewDisabled=false;
}
}
return true;
}
});
The above code doesn't make a lot of sense until you explain why you want to disable the textView
i read your use-case carefully you want to disable your TextView and want to disable it onTouch() (Correct me if i am wrong)
Here's a solution instead of using setEnabled()
as if you set it onTouch()
is not called so better to do it manually by declaring a global variable(boolean) in your (View/activity/fragment/class) where you are writing the logic.
//this as global variable
private boolean isTextViewDisabled=false;
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
return false;
}
}
return true;
}
});
Set your isTextViewDisabled to true
and false
when needed as per your use-case.
But confusion here is condition for enabling and disabling should be something else not the touch event
as according to your use case code should be like below:
//place this code on onCreate()
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN ){
if(isTextViewDisabled){
isTextViewDisabled=false;
}
}
return true;
}
});
The above code doesn't make a lot of sense until you explain why you want to disable the textView
edited Dec 31 '18 at 10:16
answered Dec 31 '18 at 9:30
AnmolAnmol
1,012623
1,012623
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
add a comment |
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
no it doesn't work
– user10524436
Dec 31 '18 at 9:44
check @Amal now
– Anmol
Dec 31 '18 at 10:17
check @Amal now
– Anmol
Dec 31 '18 at 10:17
add a comment |
try this i hope this help
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(textmail.isEnabled() == false){
textmail.setEnabled(true);
}
return true;
}
});
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
add a comment |
try this i hope this help
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(textmail.isEnabled() == false){
textmail.setEnabled(true);
}
return true;
}
});
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
add a comment |
try this i hope this help
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(textmail.isEnabled() == false){
textmail.setEnabled(true);
}
return true;
}
});
try this i hope this help
textmail.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(textmail.isEnabled() == false){
textmail.setEnabled(true);
}
return true;
}
});
answered Dec 31 '18 at 9:35
dev_ramiz_1707dev_ramiz_1707
435214
435214
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
add a comment |
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
it doesn't work
– user10524436
Dec 31 '18 at 9:44
it doesn't work
– user10524436
Dec 31 '18 at 9:44
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
please put here full code
– dev_ramiz_1707
Dec 31 '18 at 9:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985776%2fhow-to-enable-edittext-on-touch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is problem you are facing??
– Anmol
Dec 31 '18 at 9:31
1
you are returning false that's why it is not getting enabled ..return true;
– Anusha Mathur
Dec 31 '18 at 9:31
@Anmol the editText is not enabling it only work when the editText is already enabled
– user10524436
Dec 31 '18 at 9:33
@AnushaMathur even with true nothing change
– user10524436
Dec 31 '18 at 9:34
3
If the view is disabled it does not trigger OnTouchListener(), because it is disabled.
– forpas
Dec 31 '18 at 9:38