gpt4 book ai didi

java - 一项 Activity 中有 2 个 Action

转载 作者:行者123 更新时间:2023-12-01 08:53:30 25 4
gpt4 key购买 nike

我有一个带有 WebViewButtonActivity

我想在按下 Button 时转到下一个 Activity,但我不知道如何操作。

当用户点击Button时,他将被“传送”到MainActivity。我有个问题。

enter image description here

enter image description here

它被标记为红色。我不知道该怎么做。有人可以给我示例答案并更正我的代码吗?

有代码:

  package musial.pzstis.com.pzstiz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class Main10Activity extends Activity {
private WebView myWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main10);
myWebView = (WebView) findViewById(R.id.webView6);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://docs.google.com/viewer?url=http://pzstiz.swiebodzin.pl/zastepstwa/PZSTiZ_zastepstwa.pdf");
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.setInitialScale(190);
myWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
myWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);


}

@Override
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
Button button2;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Main10Activity.this, MainActivity.class));
}
});

}
}

最佳答案

Activity 中不能有 2 个 OnCreate() 方法。删除第二个onCreate()方法,并将第二个onCreate()中编写的代码复制到第一个onCreate()中。

关于java - 一项 Activity 中有 2 个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42212691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com