[英]WebView doesn't work
I'm just a beginner in Android and I started to deal with webViews. 我只是Android的初学者,所以我开始处理webViews。 Indeed, I have created two button that will take me into two different activities but when I run the application the webview doesn't load the page which is Google.com.
确实,我已经创建了两个按钮,可以将我带入两个不同的活动,但是当我运行该应用程序时,webview不会加载Google.com页面。 I already inserted the internet permission.
我已经插入了互联网许可。
Here, I did onClick method as an attribute in the button that when I click on it has to go to the twitter website. 在这里,我将onClick方法作为按钮中的一个属性,当我单击它时,它必须转到twitter网站。 I put it in a different activity class.
我把它放在另一个活动类中。
public void listen(View v)
{
Intent intent = new Intent(getApplicationContext(), onemore.class);
startActivity(intent);
}
this is the activity class 这是活动课
package com.example.aboutme;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class onemore extends Activity
{
private String uagent = "Mozilla/5.0 (Linux; U; Android 2.0; en-us;
Droid Build/ESD20) AppleWebKit/530.17
(KHTML, like Gecko) Version/4.0 Mobile
Safari/530.17";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.twomore);
displayTweets();
}
private void displayTweets()
{
WebView mWebView = (WebView) findViewById(R.id.webView1);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setUserAgentString(uagent);
mWebView.loadUrl("http://mobile.twitter.com/");
}
}
the xml layout xml布局
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView1"
/>
the manifest xml 清单xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aboutme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".WebViewActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityTwo" android:label="@string/app_name"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Do you have this line in your manifest? 您的清单中有这行吗? I did not see it, but maybe you changed the name for the SO question from ActivityTwo.
我没有看到它,但是也许您从ActivityTwo中更改了SO问题的名称。
activity android:name=".onemore">
活动android:name =“。onemore”>
Your code worked fine when I ran it. 当我运行它时,您的代码运行良好。 What was the error message you were getting?
您收到的错误消息是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.