你好:
各位大大,我是新手,想请问各位一个问题,如何判断按下不同button
显示不同的url在相同的textview中?(不好意思,文章有点笼长,敬请见谅)
以下是我的程式码:
public class MainActivity extends Activity {
TextView t1,t2;
Button btn1,btn2,btn3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = (TextView)findViewById(R.id.textView1);
t2 = (TextView)findViewById(R.id.textView2);
btn1 = (Button)findViewById(R.id.button1);
btn2 = (Button)findViewById(R.id.button2);
btn3 = (Button)findViewById(R.id.button3);
btn1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
switch (v.getId()) {
case R.id.button1:
Intent intent = new Intent(MainActivity.this,CheckOemMainActivity.class);
startActivity(intent);
}
}
});
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.button2:
Intent intent = new Intent(MainActivity.this,CheckOemMainActivity.class);
startActivity(intent);
}
}
});
btn3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.button3:
Intent intent = new Intent(MainActivity.this,CheckOemMainActivity.class);
startActivity(intent);
}
}
});
CheckOemMainActivity程式码如下:
public class CheckOemMainActivity extends Activity {
TextView t1,t2
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkoem_activity_main);
t1 = (TextView)findViewById(R.id.textView1);
t2 = (TextView)findViewById(R.id.textView2);
String url= "https://tw.yahoo.com/"
"https://www.google.com.tw/"
System.out.println("url = "+url);
t1.setText(url);
try {
t2.setText(HttpConnect(url));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我的问题是当按下button1时,textView1显示https://tw.yahoo.com/,
当按下button2时,textView1显示https://www.google.com.tw/
可否解惑 感谢..................