Android Button OnClickListener Tutorial

preview_player
Показать описание
In this tutorial you will learn how to use a button OnClickListener and make it clickable to open another activity by using intent. Here is how to do it:

and replace it with a button

- Give the button a label and we call it (Hello World) like this: android:text="Hello World"

- Now we need to position the button to the top-center of the screen like this:
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"

- To make the button clickable and perform an action we need to call setOnClickListener like this:
@Override
public void onClick(View view) {

}
});

- Now we have the button and it's clickable but it doesn't do any action, and what we really want is once the user who taps on the button will move to another page, so first we need to create an activity and resource file so that it will act as the second page like this:
click on File – New – Activity – Empty Activity then you give a name for the activity and the resource file.

- Once we have created the second activity, now we can work on the button setOnClickListener part to allow the user to move to another page.
This can be done like this:

That's it :)

Рекомендации по теме
Комментарии
Автор

Because i found no error warning when i follow your instruction, i subs this channel.

vughdeziestem
Автор

thank you so much you renewed my hopes

maisumatheus
Автор

Dude you took 5 minutes to start the tutorial. Content is good but you made it longer than what it should be

MrSpock-smdd
Автор

I have the following error in my second class, about no zero argument.... How do I fix this?

pianoLee-sxdx
Автор

the hello world thing went out years ago we have moved on

horrorfan
join shbcf.ru