如何基于另一个TextView动态更改TextView中的文本 [英] how to change text in a TextView dynamically based on another TextView
问题描述
大家早上好. 我从标题中知道所有内容都是混乱的,因此我将尝试更好地解释它. 我需要为医学项目创建一个应用来计算HbA1c.我有3个editText,其中键入了医学检验的值.三种变化中的每一种都因其他变化而改变.例如:如果我一个有42,则另一个是5.99%.等等.我试图使它们动态变化:在编写过程中仍要变化. 我尝试使用OnCliclListener,但必须编写整个值.
Good morning everyone. I know from the title it's everything confused, so I will try to explain it better. I need to create an app for a medical project to calc HbA1c. I have 3 editText in which I type values of medical test. Each of three changes because of other one. For example: if I have 42 in one, the other one is 5.99%. And so on. I'm trying to make them change dynamically: change still during I'm writing. I tried using an OnCliclListener but I have to write the entire value.
我不知道我对自己的解释是否能使您理解得好.
I don't know if I explain myself as good to make you understand.
非常感谢
推荐答案
而不是使用onClickListener
,而是尝试使用addTextChangedListener()
并在每次调用onTextChanged()
时更改TextViews.通过使用此功能,您甚至可以在键入时更改它们.
Instead of using onClickListener
, try using addTextChangedListener()
and change your TextViews whenever onTextChanged()
is called. By using this you can even change them while typing.
它看起来像这样:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence c, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence c, int i, int i2, int i3) {
if (c.length() > 0) {
} else {
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
这篇关于如何基于另一个TextView动态更改TextView中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!