如何在单击时清空edittext的值

时间:2018-02-18 22:45:41

标签: android

例如,如果我有9个edittext,我可以如何转储所选edittext的值,而不是其他的 例如edittext1 = 1,edittext2 = 2,edittext3 = 3,edittext4 = 4,edittext5 = 5,edittext6 = 6,edittext7 = 7,edittext8 = 8,edittext9 = 9 在这里我要擦除1而另一个数字仍然是

我需要你的帮助

2 个答案:

答案 0 :(得分:1)

有两种方法:

第一种方法:

edittext1.setText("");

第二种方法:

edittext1.getText().clear();

只要按一个按钮或选择editText,就可以执行此操作...例如,当您单击它时将清除您的editText

edittext1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        edittext1.getText().clear();
    }
});

另外,如果你想阻止弹出软件键盘,只需在声明editText时添加它

edittext1.setInputType(InputType.TYPE_NULL);

快乐的编码!

答案 1 :(得分:0)

点击edittext时,获取数据并清除该数据,并直接在editext框上点击事件设置值。

  'getDwollaAccount' : function(userId) {
   var dwollaCredentials = getDwollaCreden();
   const client = new dwolla.Client({
     key         : dwollaCredentials.appKey,
     secret      : dwollaCredentials.appSecret,
     environment : 'production' // optional - defaults to production
   }); // call dwolla initial api

   client.auth.client()
   .then(Meteor.bindEnvironment(function(appToken) {

    var userFound = 
    Meteor.users.findOne({'_id':userId,'profile.dwollaLocation':''});
    if(userFound){
        var requestBody = {
          firstName : userFound.profile.firstname,
          lastName  : userFound.profile.lastname,
          email     : userFound.emails[0].address
        };
        appToken
            .post('customers', requestBody)
            .then( 
                (res)=> {
                    var dwollaLocation = res.headers.get('location');;      
                    return Promise.resolve(dwollaLocation);
                }
            )
            .then(
                Meteor.bindEnvironment((dloc) =>{ 
                        return Promise.resolve(dloc);
                })
            )
            .catch(Meteor.bindEnvironment((error) => {
               console.log(error);
                              }));  
    } // end of user found
    })
    );
    },