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

Android Example Change Text On Button Click

Hey folks, in my previous post I have shared the Code of Android Example To Create Button and in this I will give you the advance level code which will change the text when button is clicked.

activity_main.xml

 
MainActivity.java
package com.junaidshahid.buttonapp;
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)
		{
			b1.setText("After Click");
		}
	}
 
 
}
 

The post Android Example Change Text On Button Click 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 Change Text On Button Click

×

Subscribe to Junaid Shahid | P-blogger

Get updates delivered right to your inbox!

Thank you for your subscription

×