我构建了一个医疗计算器应用程序,其中有很多文本,每个 TextView
都表达特定值,例如
ptn = patient name
wt = weight
hit = hight
... etc
并且可能用户在书写时忘记了他必须在文本中写什么,所以我建议一种记住他的方法,即在屏幕底部放置额外的 TextView
,这样当用户不写文本时,文本为空..然后,当他单击“ptn”时,下面的文本显示“患者姓名”,然后当他离开文本并单击下一个文本“wt”时,下面的文本会删除“患者”名称”并将其替换为“重量”..等等
并建议此代码:
e1 = (EditText) findViewById(R.id.Name);
StringV = (TextView) findViewById(R.id.StringV);
////
e1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
StringV.setText("");
}
});
e1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
StringV.setText("");
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
StringV.setText("Patient Name");
}
});
但是当运行应用程序时,结果很沮丧!
当我单击下一个文本时,下面的文本没有改变,只是当我在文本上书写时它发生变化,我希望它在我单击下一个文本时发生变化,直到完成书写并单击下一个文本..
请问该怎么做?
最佳答案
我认为你的工作可以通过简单的方式完成:
public class YourClass extends Activity implements OnClickListener{
EditText name , weight;
TextView StringV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
name = (EditText) findViewById(R.id.Name);
weight = (EditText) findViewById(R.id.Weight);
StringV = (TextView) findViewById(R.id.StringV);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.Name:
StringV.setText("Patient Name");
break;
case R.id.Weight:
StringV.setText("Weight");
break;
// write as many cases as you want
default:
StringV.setText(" ");
break;
}
}
}
如果有帮助,请不要忘记感谢并接受。
关于java - 如何在另一张纸上书写时显示文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31494539/