onclick按钮时如何清除edittext [英] How to clear the edittext when onclick on Button

查看:71
本文介绍了onclick按钮时如何清除edittext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除单击按钮时动态提供给 EditText 的数据?我该如何编写代码?我使用什么函数或方法?

How do I clear the data which is given to an EditText dynamically when clicking the button? How do I write the code? What function or method do I use?

推荐答案

尝试

 public void clear(View v) {
     edittext.setText("");
 } 

其中 clear 注册为布局文件中按钮的 onclick 处理程序,如下所示

Where clear is registered as onclick handler for the button in the layout file like this

<ImageButton android:id="@+id/ClearButton"
        android:text="@string/ClearButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="clear"           <<<--------here
        android:src="@drawable/clear"
    />

这篇关于onclick按钮时如何清除edittext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆