Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 !

Java
public void getViewId(View view){
        int id=view.getId();
        Toast.makeText(this, String.valueOf(id), Toast.LENGTH_LONG).show();
    }

id: 2131296262
HTML
<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 .
Posted
Updated 18-Jan-15 10:11am
v2

Here's my code for TextView.

1 . Reference to View
this.inputText = (TextView) findViewById(R.id.catText);


2. set text
this.inputText.setText("");
 
Share this answer
 
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 .

Java
 public void  ClearEt(View view){
    int id=view.getId();
    EditText et=(EditText)findViewById(id);
    et.setText("");

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900