Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8267591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:35:23+00:00 2026-06-08T05:35:23+00:00

I have created some buttons in XML and I have method that will onClick

  • 0

I have created some buttons in XML and I have method that will onClick open a URL. How do I link this method to my button so that on tap/onClick it will call the method.

Here’s the method code:

    public void openResource() {
     Uri uri = Uri.parse("http://librarywales.org");
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     startActivity(intent);
}

And I have created an instance of my XML Button in the onCreate method:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button libButton = (Button) findViewById(R.id.button1);
}

How do I add that method to the libButton instance?

I have now solved the above issue with the help of ‘vins’ but when I run this application on the AVD and click on a button it pops up with an android message box saying. ‘Unfortunately, ApplicationName has stopped working.’

Anyone know why this is?

Thanks,
Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:35:25+00:00Added an answer on June 8, 2026 at 5:35 am
    public class YourActivity extends Activity  implements OnClickListener {
         public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
       Button libButton =(Button) findViewById(R.id.button1);
        libButton.setOnClickListener(this);
    
        Button OtherButton =(Button) findViewById(R.id.button2);
        OtherButton.setOnClickListener(this);
    
    
       }
    
     @Override
      public void onClick(View v) {
    
        switch (v.getId()) {
        case R.id.button1: openResource();
                               break;
        case R.id.button2: //do something for second button...
    
         default : break;
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created some widgets with jQuery UI and I notice that buttons have a
I have created some JQuery that will expand a div 'popup' on hover and
I am trying to create a rich text editor. I have created some buttons
I have some code that dynamically creates a new button through JavaScript that when
I have created some functional categories that I use to show/hide markup elements. However,
I have created an Android application that includes some unit conversion tools built into
I have some buttons I am trying to create, and when I try to
I have created some python code which creates an object in a loop, and
I have created some tests in my WPF application. Right now I am working
I have created some simple charts (of type FastLine) with MSChart and update them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.