views:

69

answers:

1

I have a simple app that I'm putting together for my company. I have 4 buttons that I've created but can't seem to get them to link correctly. One button should open our mobile site, another button to call us, another button to map to us, and the final button linked to our "News" site. Any help would be greatly appreciated!

A: 

On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:

  1. To Open a Map with Certain Location

    mapButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + your-location-geo-address));
            startActivity(i);
        }
    });
    
  2. To call certain number

    callButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone-number));
            startActivity(i);
        }
    });
    
  3. To open a website

    linkButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(website-address));
            startActivity(i);
        }
    });
    

Change "location-address", "telephone-number", and "website-address" with your own String value. I hope this helps.

anmustangs
Where do I put my onclicklistener code? Also, how should the code for my button look in my main.xml file? I'm ridiculously new to this, so I apologize for not knowing what the heck I'm talking about!
SAFCU Matt
using buttons are pretty basic, have you checked Android SDK's code samples? There are a lot of samples using buttons there. http://developer.android.com/resources/samples/ApiDemos/index.html
anmustangs