如何在单击按钮时清除编辑文本 [英] How to clear the edittext when onclick on Button
本文介绍了如何在单击按钮时清除编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单击按钮时清除动态提供给 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"
/>
这篇关于如何在单击按钮时清除编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文