简体   繁体   English

我该如何参加第三项活动?

[英]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.

相关问题 如何使用arrayAdapter中的intent进入第三个活动? - How do I use intent from arrayAdapter to go into a third activity? 如何根据第一活动数据(单击单选按钮)从第二活动转到第三活动或第四活动? - How to go from second activity to third activity or fourth activity based on first activity data (Radio button clicked)? 如果在Android中注册成功,我如何进入登录活动? - How do I go to the login activity if registration is successful in Android? 避免第三项活动回到第一项活动 - Avoid third activity go back to first activity 我如何获得一个活动,而不是回到上一个活动而不是父活动? - How do I get an activity go back to the previous activity which is not the parent? 我无法做到去详细的活动 - I am unable to do to go to the detailed Activity go到Activity如何形成recycleview片段 - How do go to Activity form a recycleview fragment 如何检查我的 editText 字段是否为空并使其转到带有 Button 的新活动? - How do I check if my editText field is empty and make it go to a new activity with a Button? GWT:如何从Activity start方法中转到新位置? - GWT: how do I go to a new place from within the Activity start method? 我如何从 MainActivity 的弹出登录转到另一个活动 - how do i go from pop up login of MainActivity to another activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM