Android开发中,怎么把按钮链接到web,比如链接到百度等,在线等,急急急!!!

2025-03-25 22:29:42
推荐回答(1个)
回答1:

package com.baidu;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Baidu extends Activity {
private Button Baidu = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Baidu = (Button)findViewById(R.id.baidu);
Baidu.setOnClickListener(new MyButtonListener());
}

class MyButtonListener implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}

}
}


android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>