英文:
¿How to set automatically degree symbol in EditText?
问题
我正在Android Studio中制作一个应用程序,其中我需要捕获的数据之一是个人的体温。
如图所示,我唯一做的是在EditText中默认放置了度数符号。但是我必须手动将光标移动到符号前面的数字位置。
有人知道如何在EditText中键入温度数据后,使安卓自动将度数符号放置在之后吗?
英文:
I am making an application in android studio where one of the data that I need to capture is the temperature of the person.
As shown in the image, the only thing that I did was place the degree symbol as default in the EditText. But I have to manually move the cursor to place the number before the symbol.
Does anyone know how I can make android place the degrees symbol automatically AFTER typing the temperature data in EditText?
答案1
得分: 1
你应该在具有回调函数**afterTextChanged(Editable s)
的编辑文本上使用TextWatcher
,在此函数中,您应该通过连接方式s.toString() + your_char
**将所需的字符串/字符放在末尾。
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// 在输入温度后在此处设置数据
yourEditText.append(" °");
}
});
英文:
You should be using TextWatcher
for edit Text which has a callback function afterTextChanged(Editable s)
in which you should put your desired String/char at the end by contacting like s.toString() + your_char
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
//here you are setting the data after the entry of temprature
yourEditText.append(" \u00B0");
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论