Just place the following code in MainActivity.java package in.ruks. One by one we are going to call setOnClickListener method on each of our Button and call built-in applications. Fifth step : Our Buttons are ready to have some action, now its time to attach the event handler to them. With just the source and destination activities reversed.5. This is pretty much the same as the code in the first activity. Coding the java part of the second activity, Main2Activity.java That’s all about it in the first activity. In the second line, we have to mention the activity we are in, and run the function startActivity and pass the object’ i’ that we had created in the first line. We do that by writing in ‘MainActivity.this.’ Then we mention the class name of the activity we want to go to like this ‘Main2Activity.class’. The first one is the location where we are right now. Here, we are creating an object ‘i’ of the class intent, and then we are passing two parameters. Intent i = new Intent(MainActivity.this, Main2Activity.class) įind the entire code of MainActivity.java at the bottom of this post.įirstly the function name, ‘buttonClick,’ is the same name you gave the button in the properties under onClick.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |