Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Value of a Edit Text field

I am learning how to create UI elements. I have created a few EditText input fields. On the click of a Button I want to capture the content typed into that input field.

<EditText android:id="@+id/name" android:width="220px" /> 

That's my field. How can I get the content?

like image 846
Harsha M V Avatar asked Dec 25 '10 19:12

Harsha M V


People also ask

How do I get data from edit text Kotlin?

Open MainActivity. kt file and set OnClickListner for the button to get the user input from EditText and show the input as Toast message.

How do I get the number to edit text?

Use android:inputType="number" to force it to be numeric. Convert the resulting string into an integer (e.g., Integer. parseInt(myEditText. getText().

How do I change text value in edit?

Set the Text of Android EditText In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file. Following is the example to set the text of TextView control while declaring it in XML Layout file.


1 Answers

By using getText():

Button   mButton; EditText mEdit;  /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);      mButton = (Button)findViewById(R.id.button);     mEdit   = (EditText)findViewById(R.id.edittext);      mButton.setOnClickListener(         new View.OnClickListener()         {             public void onClick(View view)             {                 Log.v("EditText", mEdit.getText().toString());             }         }); } 
like image 122
svdree Avatar answered Sep 30 '22 03:09

svdree