Browse By

Android : EditText Example in Android Project

Few days ago, Android Studio 2.0 was released. After that, we have created Android project in Android Studio 2.0. Now, we are going to learn how to add EditText control into Android project.

EditText is an overlay over TextView that configures itself to be editable.

We have also created Android EditText Example in Eclipse.
In this tutorial, we will create the simple android project in Android Studio 2.0, which will behave like Twitter Status box.
Android : EditText Example in Android Project
We will display a number of character remaining just below to Status Box and will change color accordingly to make the user aware about status character count.

Direct Download Full Source Code


Android : EditText Example in Android Project

Create a new project and fill the required details File ⇒ New ⇒ New Project.

1. After Creating Project, open res –> layout

2. Open content_main.xml and add editext control in it as follows:

    <requestFocus />

3. Now open your

Initialize the Edittext control in it

public class MainActivity extends AppCompatActivity  {

    //ui controls
    EditText etStatus;
    TextView txtCount;

    // Init Static Members
    static int MAX_COUNT = 140;

    protected void onCreate(Bundle savedInstanceState) {

        Toolbar toolbar = (Toolbar) findViewById(;
        getSupportActionBar().setTitle("Pulse 7 Status");

        etStatus = (EditText)findViewById(;
        txtCount = (TextView)findViewById(;
  • addTextChangedListener() method is use to listen changes in EditText.
    afterTextChanged() method of TextWatcher is use to check the number of characters has been entered in Edit Text. Place below lines of code in onCreate() method.
etStatus.addTextChangedListener(new TextWatcher() {
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
    public void beforeTextChanged(CharSequence s, int start, int count,
                                  int after) {
        // TODO Auto-generated method stub
    public void af	terTextChanged(Editable s) {
        // Display Remaining Character with respective color
        int count = MAX_COUNT - s.length();
        if (count < 10) {
        if (count < 0) {

4. In AndroidManifest.xml add following in activity to adjust keyboard when activity opens.

        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />


5. Now Execute Application

This slideshow requires JavaScript.


I hope you like this article. Share your views to improve content. Please stay tune with us. In next article, we will learn Auto Complete TextView with the new version of Android Studio. Happy coding!!

Subscribe for more articles!!

Download Full Source Code