Kotlin: EditText is not getting cleared, Strange
I'm trying to reset an EditText after form submission. EditText is inside a TextInputLayout.
Xml snippet of EditText:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID *"
android:inputType="textEmailAddress"
android:textSize="10sp" />
</android.support.design.widget.TextInputLayout>
Kotlin snippet:
private lateinit var etEmail: EditText
private lateinit var tilEmail: TextInputLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_online_academy)
etEmail = findViewById(R.id.et_email)
tilEmail = findViewById(R.id.til_email)
}
I've tried different methods to clear EditText but nothing works.
Method 1:
etEmail.text.clear()
Method 2:
etEmail.text = null
Method 3:
etEmail.setText("", TextView.BufferType.EDITABLE)
Method 4:
val blank = "u0020"
etEmail.setText(blank)
Method 5:
textInputLayoutEmail.editText.text.clear()
Method 6:
etEmail.post { etEmail.text.clear() }
I'm not getting any error or warning in logcat. Form submission also works fine. Thank you.


add a comment |
I'm trying to reset an EditText after form submission. EditText is inside a TextInputLayout.
Xml snippet of EditText:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID *"
android:inputType="textEmailAddress"
android:textSize="10sp" />
</android.support.design.widget.TextInputLayout>
Kotlin snippet:
private lateinit var etEmail: EditText
private lateinit var tilEmail: TextInputLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_online_academy)
etEmail = findViewById(R.id.et_email)
tilEmail = findViewById(R.id.til_email)
}
I've tried different methods to clear EditText but nothing works.
Method 1:
etEmail.text.clear()
Method 2:
etEmail.text = null
Method 3:
etEmail.setText("", TextView.BufferType.EDITABLE)
Method 4:
val blank = "u0020"
etEmail.setText(blank)
Method 5:
textInputLayoutEmail.editText.text.clear()
Method 6:
etEmail.post { etEmail.text.clear() }
I'm not getting any error or warning in logcat. Form submission also works fine. Thank you.


you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39
add a comment |
I'm trying to reset an EditText after form submission. EditText is inside a TextInputLayout.
Xml snippet of EditText:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID *"
android:inputType="textEmailAddress"
android:textSize="10sp" />
</android.support.design.widget.TextInputLayout>
Kotlin snippet:
private lateinit var etEmail: EditText
private lateinit var tilEmail: TextInputLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_online_academy)
etEmail = findViewById(R.id.et_email)
tilEmail = findViewById(R.id.til_email)
}
I've tried different methods to clear EditText but nothing works.
Method 1:
etEmail.text.clear()
Method 2:
etEmail.text = null
Method 3:
etEmail.setText("", TextView.BufferType.EDITABLE)
Method 4:
val blank = "u0020"
etEmail.setText(blank)
Method 5:
textInputLayoutEmail.editText.text.clear()
Method 6:
etEmail.post { etEmail.text.clear() }
I'm not getting any error or warning in logcat. Form submission also works fine. Thank you.


I'm trying to reset an EditText after form submission. EditText is inside a TextInputLayout.
Xml snippet of EditText:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID *"
android:inputType="textEmailAddress"
android:textSize="10sp" />
</android.support.design.widget.TextInputLayout>
Kotlin snippet:
private lateinit var etEmail: EditText
private lateinit var tilEmail: TextInputLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_online_academy)
etEmail = findViewById(R.id.et_email)
tilEmail = findViewById(R.id.til_email)
}
I've tried different methods to clear EditText but nothing works.
Method 1:
etEmail.text.clear()
Method 2:
etEmail.text = null
Method 3:
etEmail.setText("", TextView.BufferType.EDITABLE)
Method 4:
val blank = "u0020"
etEmail.setText(blank)
Method 5:
textInputLayoutEmail.editText.text.clear()
Method 6:
etEmail.post { etEmail.text.clear() }
I'm not getting any error or warning in logcat. Form submission also works fine. Thank you.




edited Nov 22 '18 at 12:38
Zayid Mohammed
asked Nov 22 '18 at 12:29
Zayid MohammedZayid Mohammed
7821515
7821515
you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39
add a comment |
you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39
you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39
add a comment |
2 Answers
2
active
oldest
votes
First of all make sure that you have the below line in imports of your class activity:
import kotlinx.android.synthetic.main.activity_online_academy.*
In Kotlin you don't need to use findViewById
.
You can use et_email
and til_email
anywhere in your activity class code.
So just do et_email.setText("")
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
add a comment |
There is some debugging related issue to find out. Maybe some strange behavior due to your some other part of the code which is interfering or maybe just glitches on the device.
There are a few things that you can try
- First of all Just remove clearing code. And instead of clearing the edittextView just put some string to see if you are able to set string through your code. If you are able to set any string like
et_email.setText("some random string")
then just replace this line with this codeet_email.setText("")
- If it still doesn't work (you are able to set string but not able to set "" string) Then it is not just strange, It's the weird thing. You should definitely try your code in some other device or just restart your android phone or emulator.
- If you are testing in Emulator, I highly recommend Testing this in the Actual device or on New Emulator or just simply uninstalling the app and re-installing it. Cause strange and unusual behaviors (if not due to Coding or logical Errors) Are most of the time simply due to Unknown Software Issues or due to Computer infections.
- Last but not the least try to clean build or Invalidate cache and restart android studio and recompile whole code
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
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%2f53431052%2fkotlin-edittext-is-not-getting-cleared-strange%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all make sure that you have the below line in imports of your class activity:
import kotlinx.android.synthetic.main.activity_online_academy.*
In Kotlin you don't need to use findViewById
.
You can use et_email
and til_email
anywhere in your activity class code.
So just do et_email.setText("")
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
add a comment |
First of all make sure that you have the below line in imports of your class activity:
import kotlinx.android.synthetic.main.activity_online_academy.*
In Kotlin you don't need to use findViewById
.
You can use et_email
and til_email
anywhere in your activity class code.
So just do et_email.setText("")
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
add a comment |
First of all make sure that you have the below line in imports of your class activity:
import kotlinx.android.synthetic.main.activity_online_academy.*
In Kotlin you don't need to use findViewById
.
You can use et_email
and til_email
anywhere in your activity class code.
So just do et_email.setText("")
First of all make sure that you have the below line in imports of your class activity:
import kotlinx.android.synthetic.main.activity_online_academy.*
In Kotlin you don't need to use findViewById
.
You can use et_email
and til_email
anywhere in your activity class code.
So just do et_email.setText("")
answered Nov 22 '18 at 12:47
forpasforpas
15k3625
15k3625
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
add a comment |
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
removed edittext initialisation statements and imported xml layout, but still i'm not able to clear the edittext
– Zayid Mohammed
Nov 22 '18 at 13:08
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
Is this code inside the activity class?
– forpas
Nov 22 '18 at 13:12
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
yes, its inside an activity
– Zayid Mohammed
Nov 22 '18 at 13:22
Post this code.
– forpas
Nov 22 '18 at 13:29
Post this code.
– forpas
Nov 22 '18 at 13:29
add a comment |
There is some debugging related issue to find out. Maybe some strange behavior due to your some other part of the code which is interfering or maybe just glitches on the device.
There are a few things that you can try
- First of all Just remove clearing code. And instead of clearing the edittextView just put some string to see if you are able to set string through your code. If you are able to set any string like
et_email.setText("some random string")
then just replace this line with this codeet_email.setText("")
- If it still doesn't work (you are able to set string but not able to set "" string) Then it is not just strange, It's the weird thing. You should definitely try your code in some other device or just restart your android phone or emulator.
- If you are testing in Emulator, I highly recommend Testing this in the Actual device or on New Emulator or just simply uninstalling the app and re-installing it. Cause strange and unusual behaviors (if not due to Coding or logical Errors) Are most of the time simply due to Unknown Software Issues or due to Computer infections.
- Last but not the least try to clean build or Invalidate cache and restart android studio and recompile whole code
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
add a comment |
There is some debugging related issue to find out. Maybe some strange behavior due to your some other part of the code which is interfering or maybe just glitches on the device.
There are a few things that you can try
- First of all Just remove clearing code. And instead of clearing the edittextView just put some string to see if you are able to set string through your code. If you are able to set any string like
et_email.setText("some random string")
then just replace this line with this codeet_email.setText("")
- If it still doesn't work (you are able to set string but not able to set "" string) Then it is not just strange, It's the weird thing. You should definitely try your code in some other device or just restart your android phone or emulator.
- If you are testing in Emulator, I highly recommend Testing this in the Actual device or on New Emulator or just simply uninstalling the app and re-installing it. Cause strange and unusual behaviors (if not due to Coding or logical Errors) Are most of the time simply due to Unknown Software Issues or due to Computer infections.
- Last but not the least try to clean build or Invalidate cache and restart android studio and recompile whole code
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
add a comment |
There is some debugging related issue to find out. Maybe some strange behavior due to your some other part of the code which is interfering or maybe just glitches on the device.
There are a few things that you can try
- First of all Just remove clearing code. And instead of clearing the edittextView just put some string to see if you are able to set string through your code. If you are able to set any string like
et_email.setText("some random string")
then just replace this line with this codeet_email.setText("")
- If it still doesn't work (you are able to set string but not able to set "" string) Then it is not just strange, It's the weird thing. You should definitely try your code in some other device or just restart your android phone or emulator.
- If you are testing in Emulator, I highly recommend Testing this in the Actual device or on New Emulator or just simply uninstalling the app and re-installing it. Cause strange and unusual behaviors (if not due to Coding or logical Errors) Are most of the time simply due to Unknown Software Issues or due to Computer infections.
- Last but not the least try to clean build or Invalidate cache and restart android studio and recompile whole code
There is some debugging related issue to find out. Maybe some strange behavior due to your some other part of the code which is interfering or maybe just glitches on the device.
There are a few things that you can try
- First of all Just remove clearing code. And instead of clearing the edittextView just put some string to see if you are able to set string through your code. If you are able to set any string like
et_email.setText("some random string")
then just replace this line with this codeet_email.setText("")
- If it still doesn't work (you are able to set string but not able to set "" string) Then it is not just strange, It's the weird thing. You should definitely try your code in some other device or just restart your android phone or emulator.
- If you are testing in Emulator, I highly recommend Testing this in the Actual device or on New Emulator or just simply uninstalling the app and re-installing it. Cause strange and unusual behaviors (if not due to Coding or logical Errors) Are most of the time simply due to Unknown Software Issues or due to Computer infections.
- Last but not the least try to clean build or Invalidate cache and restart android studio and recompile whole code
answered Nov 22 '18 at 13:26
Abdul RehmanAbdul Rehman
1,1661325
1,1661325
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
add a comment |
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
1. I tried this already, i' not able to clear or set any text. setting hint also not working 2 & 3 . I'm not using Emulator, testing in 2 phone, both is behaving same. 4. Already tried, no change in this strange behaviour.
– Zayid Mohammed
Nov 22 '18 at 13:46
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
@ZayidMohammed try in some new activity or some new xml file. Figure out does it do for the specific activity only behavior or is it something else.
– Abdul Rehman
Nov 22 '18 at 15:13
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%2f53431052%2fkotlin-edittext-is-not-getting-cleared-strange%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
you want clear hint or text?
– sasikumar
Nov 22 '18 at 12:32
etEmail initialize code post
– sasikumar
Nov 22 '18 at 12:35
i want to clear the text which i entered while submitting the form
– Zayid Mohammed
Nov 22 '18 at 12:35
@sasikumar added the initialisation code
– Zayid Mohammed
Nov 22 '18 at 12:39