gpt4 book ai didi

android - 清除先前在 EditText 字段中输入的文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:50 27 4
gpt4 key购买 nike

嘿,我试图让我的 editText 窗口在以下任一情况下清除其内容:1) 重新选择输入不同的数据或2) 按下按钮输入预定数据

这不是提示文本。目前,一旦输入预定数据,它就会留在那里,我无法清除它,即使使用删除也是如此。我尝试使用 bool 值将 editBox.setText("") 放在 onClick 监听器和 addTextChangedListener(在方法之前和方法上)以确定代码是否已经输入,但它只是忽略它。

foodBox.addTextChangedListener(new TextWatcher(){

@Override
public void afterTextChanged(Editable s) {

}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
addFood();
valueAdded=true;
}
});


dogButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if (valueAdded==true){
foodBox.setText("");
setFood(0.0);
}
isClicked=true;
animal=1;
addFood();
valueAdded=true;//value in the box
}


});


catButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if (valueAdded){
foodBox.setText("");}
isClicked=true;
animal=2;
addFood();
valueAdded=true;
}

});
private void addFood() {
try{
aClass aob = new aClass();
setFood(0.0);
String a = this.foodBox.getText().toString();
if(isClicked&&TextUtils.isEmpty(a)){
if(animal==1){
a=mob.getDog();
}
if(animal==2){
a=mob.getCat();
}
this.foodBox.setText(a);
double d=Double.parseDouble(a);
setFood(d);
}else{
if(TextUtils.isEmpty(a)){
a="0";
}
double d=Double.parseDouble(a);
setFood(d);
}
}
catch (Exception e){
this.showAnswer.setText("Please input animals in numbers");
addFood();
}
}

谢谢

最佳答案

错误...

我用来实现 1) 的唯一代码是:

    // Clear text when clicked
host.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
host.setText("");
}
});

host 只是一个 EditText。工作正常吗?我认为你让事情变得比实际情况更复杂。

关于android - 清除先前在 EditText 字段中输入的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5898452/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com