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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With