Android Learning
HomeBlogAbout

Android Learning

Learn Android development with comprehensive tutorials, guides, and best practices. From beginner to advanced Android programming.

Quick Links

  • Home
  • Blog
  • About
  • Contact
  • Newsletter

Resources

  • Android Developers
  • Kotlin Docs
  • Jetpack Compose

© 2026 Android Learning. All rights reserved.

Privacy PolicyTerms of Service
Back to Blog
February 23, 2016
4 min read
Akshay Raj

Building A Simple Android Application Part – 2

Building A Simple Android Application Part – 2

Akshay Raj

Android development expert

After completing the previous lesson, you have an android application that shows an activity with a text field and a button. In this lesson, you’ll add some code to MainActivity that show a Toast Message when the user clicks the Submit button.

Respond to the Submit Button

  1. In the java/akraj.snow.test directory, open the MainActivity.java file.
  2. Within the MainActivity class, add the <EditText> and <Button> method, use findViewById() to get the EditText and Button element.
    EditText editText = (EditText)findViewById(R.id.edit_message);
    Button button = (Button)findViewById(R.id.button);
  3. You may use OnClickListener to get results, when the user clicks on the Submit button.
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        }
    });
  4. Get the text from <EditText> element, use the getText() method in String variable.
    String text = editText.getText().toString();
  5. Add Toast method to show EditText value to Toast Message.
    Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
In Android Studio, press Alt + Enter (option + return on Mac) to import missing classes.

Complete Code

package akraj.snow.test;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    EditText editText;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        editText = (EditText) findViewById(R.id.edit_message);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String text = editText.getText().toString();
                Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

Run Your App

post4

Tags

#android#first android app

Comments

No comments yet.

Enjoyed this article?

Subscribe to our newsletter to get more articles like this delivered to your inbox.