[英]How do I go to a third activity?
I read on here how to go from the MainActivity to a second activity, unfortunately I still don't fully understand what's going on, because if I use the same code to go from the second activity to a third it won't work, so, yeah copying code without understanding is always a problem. 我在这里阅读了如何从MainActivity转到第二个活动,不幸的是,我仍然不完全了解发生了什么,因为如果我使用相同的代码从第二个活动转到第三个活动,它将无法正常工作,因此,是的,在不理解的情况下复制代码始终是一个问题。 So, in general what's the easiest most basic way to just go from activity to activity to activity.
因此,总的来说,从一项活动到另一项活动再到另一项活动,最简单,最基本的方法是什么。 In other words for now I want let's say 5 activities I can jump back and forth through by pressing a button.
换句话说,现在我想说5个活动,我可以通过按一个按钮来回跳动。
package com.example.human.hurdlesb;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity2Activity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
Button btnScreen3 = (Button) findViewById(R.id.btnScreen3);
btnScreen3.setOnClickListener(this);
}
it complains that "view cannot be applied to...('this' seems to be the problem although the same code works in the MainActivity class 它抱怨说“视图不能应用于...(虽然这在MainActivity类中可以使用相同的代码,但这似乎是一个问题。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate ...
getMenuInflater().inflate(R.menu.menu_main_activity2, 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);
}
and overriding the superclass seems to be another problem... 覆盖超类似乎是另一个问题...
@Override
public void onClick(View view) {
Log.i("click", "you clicked");
Intent i = new
Intent(MainActivity2Activity.this,MainActivity3Activity.class);
startActivity(i);
}
}
The code you have stated will not compile because MainActivity2Activity
needs to implement the View.OnClickListener
interface. 您声明的代码将无法编译,因为
MainActivity2Activity
需要实现View.OnClickListener
接口。 The onClick()
method that you override comes from this interface and without implementing it, you cannot override the method. 您重写的
onClick()
方法来自此接口,并且没有实现它,就无法覆盖该方法。 Hence your compilation failure. 因此,您的编译失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.