有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用WebView onTouchListener Android链接到另一个活动

我在这个主页上设置了多个Web视图。基本上,这个想法很简单。我使用三种网络视图,它们都从一个在线网站获取不同的内容。当他们点击web视图时,它会将他们带到另一个活动。那剩下的就交给我吧。我只需要帮助使用onTouchListener将web视图链接到另一个活动

这是我的Java文件:查找// THE CODE FOR THE OnTOUCHEVETN STARTS HERE!行。这就是我尝试webview 1启动第二个活动的地方。我试图使用:Intent myIntentActivity1 = new Intent(this, ReadComments.Class);但是java给了我以下错误:

Remove arguments to match 'Intent()'

package com.testapp;

import com.testapp.R.menu;

import 安卓.app.Activity;
import 安卓.content.Intent;
import 安卓.net.Uri;
import 安卓.os.Bundle;
import 安卓.view.MotionEvent;
import 安卓.view.View;
import 安卓.view.View.OnClickListener;
import 安卓.view.View.OnTouchListener;
import 安卓.webkit.WebView;
import 安卓.webkit.WebViewClient;
import 安卓.widget.Button;
import 安卓.widget.ImageView;

public class mainlogin extends Activity implements OnClickListener{

private Button  mRegister, mlogin, mcontactus;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlogin);


    ImageView img = (ImageView)findViewById(R.id.centennialmsssite);
    img.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("http://mywebsite.com"));
            startActivity(intent);
        }

    });

    WebView wv = (WebView)findViewById(R.id.my_webview);
    wv.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);


            return true;
            }
    });

    wv.loadUrl("http://mywebsite.com/main-content");

    // THE CODE FOR THE OnTOUCHEVETN STARTS HERE!

    WebView wv1 = (WebView)findViewById(R.id.topic_one);
    wv1.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);


            return true;
            }
    });

    wv1.loadUrl("http://mywebsite.com/content-one");

    wv1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP){

                Intent myIntentActivity1 = new Intent(this, ReadComments.Class);
                //call N_X and wait for result
                startActivity(myIntentActivity1);

                return true;
            }
            return false;
        }
    });

    // IT ENDS HERE!

    WebView wv2 = (WebView)findViewById(R.id.topic_two);
    wv2.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);


            return true;
            }
    });

    wv2.loadUrl("http://mywebsite.com/content-two");

    WebView wv3 = (WebView)findViewById(R.id.topic_three);
    wv3.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);


            return true;
            }
    });

    wv3.loadUrl("http://mywebsite.com/content-three");

    mRegister = (Button)findViewById(R.id.btn_register);
    mRegister.setOnClickListener(this);

    mlogin = (Button)findViewById(R.id.btn_login);
    mlogin.setOnClickListener(this);

    mcontactus = (Button) findViewById(R.id.btn_contact_us);
    mcontactus.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btn_login:
        Intent i = new Intent(this, Login.class);
        startActivity(i);
        break;
    case R.id.btn_register:
        Intent i1 = new Intent(this, Register.class);
        startActivity(i1);
        break;
    case R.id.btn_contact_us:
        Intent i2 = new Intent(this, contactus.class);
        startActivity(i2);
        break;
    default:
        break;
    }

}
}

这是我的XML文件:

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@drawable/background"
安卓:orientation="vertical" >

<Button
    安卓:id="@+id/btn_register"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignBaseline="@+id/btn_login"
    安卓:layout_alignBottom="@+id/btn_login"
    安卓:layout_alignRight="@+id/textView1"
    安卓:background="#333333"
    安卓:minHeight="40dp"
    安卓:minWidth="140dp"
    安卓:text="@string/mainpage_register_button"
    安卓:textColor="#999999" />

<Button
    安卓:id="@+id/btn_login"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignLeft="@+id/textView1"
    安卓:layout_below="@+id/textView1"
    安卓:layout_marginTop="280dp"
    安卓:background="#333333"
    安卓:minHeight="40dp"
    安卓:minWidth="140dp"
    安卓:text="@string/main_button_login"
    安卓:textColor="#999999" />

<Button
    安卓:id="@+id/btn_contact_us"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignLeft="@+id/btn_login"
    安卓:layout_alignRight="@+id/btn_register"
    安卓:layout_below="@+id/btn_register"
    安卓:background="#333333"
    安卓:minHeight="40dp"
    安卓:layout_marginTop="2dp"
    安卓:text="@string/mainpage_contact_us"
    安卓:textColor="#999999" />

<ImageView
    安卓:id="@+id/centennialmsssite"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignLeft="@+id/btn_contact_us"
    安卓:layout_below="@+id/btn_contact_us"
    安卓:layout_marginTop="14dp"
    安卓:contentDescription="@string/mss_button_description"
    安卓:src="@drawable/msswebsitebutton" />

<TextView
    安卓:id="@+id/textView1"
    安卓:layout_width="286dp"
    安卓:layout_height="wrap_content"
    安卓:layout_alignParentTop="true"
    安卓:layout_centerHorizontal="true"
    安卓:layout_marginTop="14dp"
    安卓:gravity="center"
    安卓:text="@string/welcome_mainpage"
    安卓:textAppearance="?安卓:attr/textAppearanceLarge"
    安卓:textColor="#ffffff"
    安卓:textStyle="bold" />

<WebView
    安卓:id="@+id/my_webview"
    安卓:layout_width="match_parent"
    安卓:layout_height="40dp"
    安卓:layout_alignLeft="@+id/textView1"
    安卓:layout_alignRight="@+id/sitebutton"
    安卓:layout_below="@+id/textView1"
    安卓:layout_marginTop="12dp"
    安卓:maxHeight="40dp"
    安卓:minHeight="40dp" />

<WebView
    安卓:id="@+id/topic_one"
    安卓:layout_width="match_parent"
    安卓:layout_height="70dp"
    安卓:layout_alignLeft="@+id/my_webview"
    安卓:layout_alignRight="@+id/my_webview"
    安卓:layout_below="@+id/my_webview"
    安卓:layout_marginTop="5dp"
    安卓:maxHeight="70dp"
    安卓:minHeight="70dp" />

<WebView
    安卓:id="@+id/topic_two"
    安卓:layout_width="match_parent"
    安卓:layout_height="70dp"
    安卓:layout_alignLeft="@+id/topic_one"
    安卓:layout_alignRight="@+id/topic_one"
    安卓:layout_below="@+id/topic_one"
    安卓:maxHeight="70dp"
    安卓:minHeight="70dp" />

    <WebView
        安卓:id="@+id/topic_three"
        安卓:layout_width="match_parent"
        安卓:layout_height="70dp"
        安卓:layout_alignLeft="@+id/topic_two"
        安卓:layout_alignRight="@+id/topic_two"
        安卓:layout_below="@+id/topic_two"
        安卓:maxHeight="70dp"
        安卓:minHeight="70dp" />

</RelativeLayout>

是什么导致了这个错误


共 (1) 个答案

  1. # 1 楼答案

    试试这个-

    Intent myIntentActivity1 = new Intent(mainlogin.this, ReadComments.class);
    startActivity(myIntentActivity1);
    

    Intent myIntentActivity1 = new Intent(getBaseContext(), ReadComments.class);
    startActivity(myIntentActivity1);