Display TextView when EditText is not empty
I'm working with an Android application and have encountered the following problem.
Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).
What I have done:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text")
}
return rootView;
}
This does not work. The text view never pops up. Any ideas why?
add a comment |
I'm working with an Android application and have encountered the following problem.
Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).
What I have done:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text")
}
return rootView;
}
This does not work. The text view never pops up. Any ideas why?
add a comment |
I'm working with an Android application and have encountered the following problem.
Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).
What I have done:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text")
}
return rootView;
}
This does not work. The text view never pops up. Any ideas why?
I'm working with an Android application and have encountered the following problem.
Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).
What I have done:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text")
}
return rootView;
}
This does not work. The text view never pops up. Any ideas why?
edited Nov 19 '18 at 11:12
Fantômas
32.5k156388
32.5k156388
asked Nov 19 '18 at 9:24
JohnJohn
718
718
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
}
}
};
edittextbox1.addTextChangedListener(textWatcher);
edittextbox2.addTextChangedListener(textWatcher);
add a comment |
You need to use something like this to listen to your EditText fields.
edittextbox1 = (EditText)findViewById(R.id.editText);
edittextbox1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
});
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
add a comment |
pls try set visibility of your textview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text");
textview.setVisibility(View.VISIBLE);
}
return rootView;
}
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
add a comment |
Do it like this. It will work!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);
if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
} else {
textView.setVisibility(View.GONE);
}
return rootView;
}
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%2f53371579%2fdisplay-textview-when-edittext-is-not-empty%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
}
}
};
edittextbox1.addTextChangedListener(textWatcher);
edittextbox2.addTextChangedListener(textWatcher);
add a comment |
Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
}
}
};
edittextbox1.addTextChangedListener(textWatcher);
edittextbox2.addTextChangedListener(textWatcher);
add a comment |
Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
}
}
};
edittextbox1.addTextChangedListener(textWatcher);
edittextbox2.addTextChangedListener(textWatcher);
Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
}
}
};
edittextbox1.addTextChangedListener(textWatcher);
edittextbox2.addTextChangedListener(textWatcher);
edited Nov 19 '18 at 9:47
answered Nov 19 '18 at 9:39
Faysal AhmedFaysal Ahmed
3,64141230
3,64141230
add a comment |
add a comment |
You need to use something like this to listen to your EditText fields.
edittextbox1 = (EditText)findViewById(R.id.editText);
edittextbox1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
});
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
add a comment |
You need to use something like this to listen to your EditText fields.
edittextbox1 = (EditText)findViewById(R.id.editText);
edittextbox1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
});
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
add a comment |
You need to use something like this to listen to your EditText fields.
edittextbox1 = (EditText)findViewById(R.id.editText);
edittextbox1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
});
You need to use something like this to listen to your EditText fields.
edittextbox1 = (EditText)findViewById(R.id.editText);
edittextbox1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int st, int b, int c)
{
}
@Override
public void beforeTextChanged(CharSequence s, int st, int c, int a)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
@Override
public void afterTextChanged(Editable s)
{
if(edittextbox1.getText().toString().length() !=0) {
textview.setText("some text")
}
}
});
answered Nov 19 '18 at 9:32
JantzillaJantzilla
4451416
4451416
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
add a comment |
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?
– John
Nov 19 '18 at 9:39
add a comment |
pls try set visibility of your textview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text");
textview.setVisibility(View.VISIBLE);
}
return rootView;
}
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
add a comment |
pls try set visibility of your textview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text");
textview.setVisibility(View.VISIBLE);
}
return rootView;
}
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
add a comment |
pls try set visibility of your textview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text");
textview.setVisibility(View.VISIBLE);
}
return rootView;
}
pls try set visibility of your textview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...
if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text");
textview.setVisibility(View.VISIBLE);
}
return rootView;
}
answered Nov 19 '18 at 9:27
ManishManish
4091620
4091620
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
add a comment |
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
this either won't work because he needs to listen to text changes
– Vladyslav Matviienko
Nov 19 '18 at 9:31
add a comment |
Do it like this. It will work!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);
if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
} else {
textView.setVisibility(View.GONE);
}
return rootView;
}
add a comment |
Do it like this. It will work!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);
if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
} else {
textView.setVisibility(View.GONE);
}
return rootView;
}
add a comment |
Do it like this. It will work!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);
if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
} else {
textView.setVisibility(View.GONE);
}
return rootView;
}
Do it like this. It will work!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);
if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
textView.setVisibility(View.VISIBLE);
textview.setText("some text");
} else {
textView.setVisibility(View.GONE);
}
return rootView;
}
edited Nov 19 '18 at 11:15
LordParsley
2,17611730
2,17611730
answered Nov 19 '18 at 9:36
Noorul HaarishaNoorul Haarisha
141
141
add a comment |
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%2f53371579%2fdisplay-textview-when-edittext-is-not-empty%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