0

我已经尝试解决这个问题好几天了,我已经搜索了网络,也搜索了这里提供的许多相关问题,但我还没有解决这个问题。

当我创建一个单独的项目时,代码工作正常,但由于某种原因它在这里不起作用。

我有几个可以访问的活动,从主页单击一个按钮(这部分工作正常),然后从这几个活动中的每一个中,我都有一些按钮,当单击时应该打开一个网站,但它没有发生.. ...

我已将所有活动添加到清单中(我能看到的)已经看了好几次。哈哈

我已经重做了几次代码,但无济于事,我唯一没有做的就是从头开始项目(不得已)。

感谢你的帮助。

** MainActivity.java(主页工作正常)

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class MainActivity extends Activity {
    ImageButton imagebutton1, imagebutton2,imagebutton3, imagebutton4,
    imagebutton5, imagebutton6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }

    public void addListenerOnButton() {

        final Context context = this;

        imagebutton1 = (ImageButton) findViewById(R.id.imageButton1);

        imagebutton1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, Fashion.class);
                            startActivity(intent);   

            }
        }); 


            imagebutton2 = (ImageButton) findViewById(R.id.imageButton2);

            imagebutton2.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    Intent intent = new Intent(context, Electrical.class);
                                startActivity(intent);   

                }

        });

            imagebutton3 = (ImageButton) findViewById(R.id.imageButton3);

            imagebutton3.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    Intent intent = new Intent(context, Kids.class);
                                startActivity(intent);   

                }
            }); 


                imagebutton4 = (ImageButton) findViewById(R.id.imageButton4);

                imagebutton4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent intent = new Intent(context, Pets.class);
                                    startActivity(intent);   

                    }

            });

                imagebutton5 = (ImageButton) findViewById(R.id.imageButton5);

                imagebutton5.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent intent = new Intent(context, Food.class);
                                    startActivity(intent);   

                    }

                });

                imagebutton6 = (ImageButton) findViewById(R.id.imageButton6);

                imagebutton6.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent intent = new Intent(context, Web.class);
                                    startActivity(intent);   

                    }

                });
    }
}

**

MainActivityWebview.java 

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

    public class MainActivityWebView extends Activity {

        private Button button1, button2;

        public void onCreate(Bundle savedInstanceState) {
            final Context context = this;

            super.onCreate(savedInstanceState);
            setContentView(R.layout.fashion);

            button1 = (Button) findViewById(R.id.button1);

            button1.setOnClickListener(new OnClickListener() {

              @Override
              public void onClick(View arg0) {
                Intent intent = new Intent(context, WebViewActivitySelfridges.class);
                startActivity(intent);
              }

            });
            button2 = (Button) findViewById(R.id.button2);

            button2.setOnClickListener(new OnClickListener() {

              @Override
              public void onClick(View arg0) {
                Intent intent = new Intent(context, WebViewActivityVery.class);
                startActivity(intent);
              }

            });


        }

    }

时尚.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"

        >
    <ScrollView
            android:id="@+id/tabscrvie"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
            <TableLayout 
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

               <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/selfridges" />

                <Button
                    android:id="@+id/button1"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Store" />

    </TableRow>

            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/very" />

                <Button
                    android:id="@+id/button2"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

           <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/nelly" />

                <Button
                    android:id="@+id/button3"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/george" />

                <Button
                    android:id="@+id/button4"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView5"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/redoute" />

                <Button
                    android:id="@+id/button5"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView6"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/fraser" />

                <Button
                    android:id="@+id/button6"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView7"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/lncc" />

                <Button
                    android:id="@+id/button7"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

     <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

               <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/selfridges" />

                <Button
                    android:id="@+id/button1"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Store" />

    </TableRow>

            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/very" />

                <Button
                    android:id="@+id/button2"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

           <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:src="@drawable/nelly" />

                <Button
                    android:id="@+id/button3"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/george" />

                <Button
                    android:id="@+id/button4"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView5"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/redoute" />

                <Button
                    android:id="@+id/button5"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView6"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/fraser" />

                <Button
                    android:id="@+id/button6"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView7"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="20dp"
                    android:layout_weight="1"
                    android:baselineAlignBottom="false"
                    android:cropToPadding="true"
                    android:src="@drawable/lncc" />

                <Button
                    android:id="@+id/button7"
                     android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1"
                    android:text="Visit Website" />

    </TableRow>



    </TableLayout>
    </ScrollView>
    </RelativeLayout>

WebViewActivitySelfridges.java

import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;

    public class WebViewActivitySelfridges extends Activity {

        private WebView webView;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);

            webView = (WebView) findViewById(R.id.webView1);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("http://www.selfridges.com/");

        }

    }

WebViewActivityVery.java

import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;

    public class WebViewActivityVery extends Activity {

        private WebView webView;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);

            webView = (WebView) findViewById(R.id.webView1);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("http://www.very.co.uk/");

        }

    }

webview.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

显现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="store.front"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="store.front.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="store.front.WebViewActivitySelfridges" >
        </activity>

         <activity
            android:label="@string/app_name"
            android:name="store.front.WebViewActivityVery" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="store.front.Fashion" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="store.front.Electrical" >
        </activity>

        <activity
            android:label="@string/app_name"
            android:name="store.front.Kids" >
        </activity>

         <activity
            android:label="@string/app_name"
            android:name="store.front.Food" >
        </activity>

         <activity
            android:label="@string/app_name"
            android:name="store.front.Pets" >
        </activity>

         <activity
            android:label="@string/app_name"
            android:name="store.front.Web" >
        </activity>

         <activity
            android:label="@string/app_name"
            android:name="store.front.MainActivityWebView" >
        </activity>



     </application>

</manifest>
4

1 回答 1

0

不完全确定这是否正确。

您定义的所有 webview 活动的 onCreate 中都缺少 @Override。

检查 onCreate() 是否被触发。

于 2013-07-19T07:45:56.387 回答