askIT

Android Get text from EditText

Use "findViewById" to get text from a EditText.

Example to get text from EditText

EditText editTextName = (EditText)findViewById(R.id.editTextName);
String editTextNameString = editTextName.getText().toString();

In the example we define a EditText by finding it in the design. In Design we have a EditText element with id "editTextName".

01_edittext_design.jpg

You can convert a EditText to a string with the following code:
editTextName.getText().toString();

MainActivity

package com.nettport.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);

                EditText editTextName = (EditText)findViewById(R.id.editTextName);
                String editTextNameString = editTextName.getText().toString();

        }
}

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.