如何2个按钮链接到eclpse 2个不同的HTML链接? [英] How to link 2 buttons to 2 different html links in eclpse?
本文介绍了如何2个按钮链接到eclpse 2个不同的HTML链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经建立2个按钮,我想他们都连接到2个不同的HTML链接,但我可以通过使用下面这个code只能链接的....
I have created 2 buttons and i want to link both of them to 2 different html links,but i could link only one by using this below code....
包com.kk24.adding两个按钮;
package com.kk24.adding two buttons;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;
import android.net.Uri;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://........."));
startActivity(myWebLink);
}
});
}
现在我想按钮2链接到另一个链接我们怎么联系????
Now i want to link button 2 to another link how do we link ????
给我一步一步的详细信息,如果有什么导入或创建一个类左右.....
Give me step by step details if there is something to import or creating a class or so.....
先谢谢了。
推荐答案
试试这个code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://link1."));
startActivity(myWebLink);
}
});
Button btn2 = (Button) findViewById(R.id.button2);
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myWebLink2 = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink2.setData(Uri.parse("http://link2."));
startActivity(myWebLink2);
}
});
这篇关于如何2个按钮链接到eclpse 2个不同的HTML链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文