布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.sanweek.MainActivity"
android:orientation="vertical">
<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
代码
xListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this,MainActivity2.class);
intent.putExtra("web","http://www.baidu.com");
startActivity(intent);
}
});
public class MainActivity2 extends AppCompatActivity{
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent intent = getIntent();
String web = intent.getStringExtra("web");
wv = (WebView) findViewById(R.id.wv);
wv.loadUrl(web);
WebSettings settings = wv.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient());
}
}