Android: Image button as a hyperlink, phone call, map directions?
Solution 1
On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:
-
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); } });
-
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); } });
-
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.
Solution 2
anmustangs answer is very good, but one thing I would like to add for the button you are making for a link to your site, where anmustangs wrote (website-address) instead of just typing in a site, it needs to put formatted correctly. For example, you can use "http://www.google.com" and yes you do need to use the quotation marks I put in there. I know I am years late to this thread but who knows who my post may help.
Related videos on Youtube
SAFCU Matt
Updated on May 04, 2022Comments
-
SAFCU Matt almost 2 years
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!
-
Mark B over 13 yearsWhat have you accomplished so far? Where are you having trouble?
-
-
SAFCU Matt over 13 yearsWhere 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!
-
Muhammad Abdullah over 13 yearsusing buttons are pretty basic, have you checked Android SDK's code samples? There are a lot of samples using buttons there. developer.android.com/resources/samples/ApiDemos/index.html