如何在android中清除EditText的内容? [英] how to clear EditText's Content in android ?
问题描述
public void getViewId(View view){
int id = view.getId();
Toast.makeText( this , String .valueOf(id),Toast.LENGTH_LONG)。节目();
}
id:2131296262
< EditText
android:id = @ + id / etUserName
android:layout_width = fill_parent
android:layout_height = fill_parent
android:gravity = center
android:layout_marginLeft = @ dimen / first_input_margin
< span class =code-attribute> android:layout_marginRight = @ dimen / first_input_margin
android:layout_marginBottom = @ dimen / first_input_margin
android:layout_marginTop = @ dimen / first_input_margin
< span class =code-attribute> android:textSize = < span class =code-keyword> @ dimen / first_input_txt
android:已删除 = @ color / White
android:text = 输入您的用户名
android:/ >
因为你看到id是etUserName而不是数字id!我认为这个数字在运行时被固定到EditText。
我可以清除这个数字ID的EditText的内容吗?或者我必须改变我的方法?谢谢你告诉我。
这是我的TextView代码。
1。参考视图
this.inputText =(TextView)findViewById(R.id.catText);
2.设置文本
this.inputText.setText();
< blockquote>我找到了。这是我的解决方案。
因为你知道我有多个EditText。但我们的方法必须清除用户点击的EditText。
你唯一应该做的就是获取id并使用它来清除特定的编辑文本。
i认为android在运行时为每个活动元素生成一个数字id 。此ID与您用于查看的ID不同。这是一个数字ID,而且这个id也是唯一的。
public void ClearEt(查看视图){
int id = view.getId();
EditText et =(EditText)findViewById(id);
et.setText( );
}
hi guys . iam working on my android application . i created an activity . this activity has two EditText . one of them is used for User name and another one for password . now I want to create a method to clear (Edit Text) which is clicked by user . i tried to get (EditText)'s id . i thought , if i have (EditText)'s id , i can remove the content but it did'nt work . surprisingly i got an exotic id . i used this method to get EditText's id but it Showed me a number ! i didnt use this number as id at all !
public void getViewId(View view){
int id=view.getId();
Toast.makeText(this, String.valueOf(id), Toast.LENGTH_LONG).show();
}
id: 2131296262
<EditText
android:id="@+id/etUserName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_marginLeft="@dimen/first_input_margin"
android:layout_marginRight="@dimen/first_input_margin"
android:layout_marginBottom="@dimen/first_input_margin"
android:layout_marginTop="@dimen/first_input_margin"
android:textSize="@dimen/first_input_txt"
android:removed="@color/White"
android:text="Enter your User Name"
android:/>
as you see the id is "etUserName" not a numeric id ! i think this number is fastened to EditText during the run time .
can i clear EditText's Content whit this numeric id ? or i have to change my method ? thank you for letting me know .
Here's my code for TextView.
1 . Reference to View
this.inputText = (TextView) findViewById(R.id.catText);
2. set text
this.inputText.setText("");
i found it . this is my solution .
as you know i have more than one EditText . but our method has to clear EditText which is clicked by user .
the only thing you should do is to get id and use it to clear specific Edit Text .
i think android produce a numeric id for every Elements in activity during the Run time . this id is not same as id which you used for view . this is a numeric id , and also this id is unique .
public void ClearEt(View view){ int id=view.getId(); EditText et=(EditText)findViewById(id); et.setText(""); }
这篇关于如何在android中清除EditText的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!