你好:
各位大大,我是新手,想請問各位一個問題,如何判斷按下不同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/
可否解惑 感謝..................