Android Button

In my last example we have discussed about the text view. Now we are moving towards the button control.

Now add button control to the android activity.

		android button
		Figure 1
		

Now move to its xml coding

		android button xml code
		Figure 2
		

Here you can change the text of the button and id of the button. Which you can also change by double clicking on button.

Let’s I have set the button id b1 and button text click me.

Add click event to the button

Now I want to add button even onclick. So I have created a function in java file which is related to this activity and bind this function with button onclick event.

		public void btn_click(View v)
{
    
    
    
}

		android button click event
		Figure 3
		

Now change the text of textview on button click

		public void btn_click(View v)
    {

TextView t1=(TextView)findViewById(R.id.txt_data);
        t1.setText("button has been clicked");

    }

		

Now execute the code

		android button out put
		Figure 4
		
		android button out put after click
		Figure 5
		

Email Address

For any query you can send mail at info@techaltum.com