How to Toast in Android – UI Widget

Posted on .
android-cover-720x340

DOWNLOAD CODE

Toast in Android is something in  which developer can see their result’s ,ouput’s . lets code ….

1). First take Button in  activity_main.xml . After Taking Button in xml file go for MainActivity.java file .

2) . MainActivity.java

package androidarena.simpletoast;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Button b = (Button)findViewById(R.id.button1);
		b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				Toast.makeText(getApplicationContext(), "WOOOOh !!!! My TOAST IS WORKING", 5000).show();
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

Output – toast output   For more queries and tutorials visit my other tutorials and do comment and post here 🙂 happy coding :p

One thought on “How to Toast in Android – UI Widget

Leave a Reply

Your email address will not be published. Required fields are marked *