Android Push Onclick Event

Posted on 36 views
In this example, I volition demo yous 2 methods to grip push onClick consequence inward android. Handling android push onClick listener is non much hard only many novel developers instruct work amongst onClick method in addition to search for solution. So, hither I’m going to demo 2 best methods to grip onClick inward android push in addition to close all developers role these methods to grip onClick.

Android Menu – Handling Option Menu Item Click
Buttons – Android Button Examples

Create a novel Android Project

Application Name: Android Button onClick
Company Domain:
Package Name: com.viralandroid.androidbuttononclick
Minimum SDK: Android 2.2 (API viii Froyo)

Add 2 buttons to your XML activity layout file

I’m going to demo yous 2 types of on click inward android button. So, showtime yous accept to add together 2 buttons inward your xml layout file in addition to your code looks similar this.

Add coffee code

If yous accept a push amongst id inward XML file similar to a higher house minute push of activity_main.xml file, your coffee code looks similar this.

Button push = (Button) findViewById(;         button.setOnClickListener(new View.OnClickListener() {             @Override             world void onClick(View view) {                 // This Perform activity on click                 Intent intent = novel Intent(view.getContext(), SecondActivity.class);                 startActivity(intent);             }         });

Instead of this, yous tin forcefulness out grip click past times adding onClick attribute inward your XML file similar inward the showtime push of activity_main.xml file in addition to your coffee code volition hold off similar this.

public void firstButtonClick(View v) {         Toast.makeText(this, "Clicked on Button", Toast.LENGTH_LONG).show();     }

I intend this method is unproblematic to role in addition to tardily to understand.

READ  most amazing new technology gadgets आश्‍चर्य चकित करने वाली तकनीकें और गैजेट

If yous confront work to implement to a higher house 2 methods to grip on click inward android button, hold off at the code given below. Here, I accept provided other all necessary XML in addition to Java file code.

Complete code of file looks similar this.

Create a novel in addition to a second_activity.xml file which are following.


And modified code of AndroidManifest.xml like this.

Finally, yous accept done. Run your Android Button onClick application which looks similar this.

 I volition demo yous 2 methods to grip push onClick consequence inward android Android Button onClick Event

Download Complete Example Project

Download consummate Android Button onClick project root code from GitHub.