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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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.
回答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.