Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Android Example To Create Toast

Hey folks, in my previous post, I have shared Android Example Change Text On Button Click and now I’m sharing Android Example To Create Toast. This is just because if you want to give any hint to the user of the application, like button is pressed, you are login successfully etc.

activity_main.xml


 

MainActivity:-

package com.junaidshahid.toastapp;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.view.Menu;
 
public class MainActivity extends Activity implements OnClickListener
{ 
	Button b1;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
 
		b1=(Button)findViewById(R.id.button1);
		b1.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v)
	{
		if(v.getId()==R.id.button1)
		{
			Toast.makeText(getApplicationContext(),"Welcome To Junaid's Blog,",Toast.LENGTH_SHORT).show();
		}
	}
 
 
}

SYNTAX:-

Toast.makeText(getApplicationContext(),"Text To Display",Toast.LENGTH_SHORT).show();
 

The post Android Example To Create Toast appeared first on Junaid Shahid | P-Blogger.



This post first appeared on Junaid Shahid | P-Blogger, please read the originial post: here

Share the post

Android Example To Create Toast

×

Subscribe to Junaid Shahid | P-blogger

Get updates delivered right to your inbox!

Thank you for your subscription

×