How to create Simple Toast in Android

Android is one of the mobile system operation that have basic open source. We can costum our smartphone that include android system operation, like change or modif SystemUI in every android smartphone. It can make your mobile android look like fresh again. amazing you can do anything with android.

Now, i'll give a new post about How to create Simple Toast in Android. Do you know what is this? Oke i'll tell it. Toast is the message notification in android appears few second after giving a touch. for example you can see bellow:

toast notification in android

Now, i think you have understood about toast notification in android. Now you'll have a ask, How to make toast notification in android, especiallly use an eclipse?. in my post, i give you How to create Simple Toast in Android without button, but it will appear if you push enter. Don't worry guys, i have maked a post about how to make simple toast notification in android. 

Now check this out How to create Simple Toast in Android!

1. As usuall, you must prepare eclipse tool and make a new project

2. make activity_main.xml like picture bellow :

activity main xml toast

   Note: make a edit text in eclipse and make id it same like pictucre
  
3. Now, you're making code in java, and make MainActivity.java like bellow:

MainActivity.java
 
package com.example.toast;

import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
import android.view.View;
import android.widget.EditText;
import android.view.View.OnKeyListener;
import android.view.KeyEvent;

public class MainActivity extends Activity {
private EditText edittext;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  addKeyListener();
 }
 
 public void addKeyListener(){
  //memperoleh edittext
  edittext = (EditText) findViewById(R.id.editText1);
  edittext.setOnKeyListener(new OnKeyListener() {
   
   @Override
   public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((event.getAction()==KeyEvent.ACTION_DOWN) && (keyCode==KeyEvent.KEYCODE_ENTER)){
     Toast.makeText(MainActivity.this, edittext.getText(), Toast.LENGTH_LONG).show();
     return true;
    }
    return false;
   }
  });
 }
 
}



you must know this notes:

- private EditText is used to make project first appear is activty_main.xml
- public void addKeyListener is used to make function search input by id edittext
- public boolean OnKey is used to make enter button keyboard has function to appear toast notification

4. If you have finished, save and run!

5. is it simple toturial? i think so. and try this, i hope you will be succes.

Oke that's all about how to make simple toast notification in android. You can try to make a project more than it. Show your creativity and always try and try..good luck!

2 Responses to "How to create Simple Toast in Android"