如何使用按钮正确调用几个类(意图)?

时间:2011-01-21 09:07:35

标签: android class button android-intent oncreate

我是Java Android开发的初学者。我正在使用Eclipse SDK 3.6.1版本。我正在尝试调用新的意图,但我的应用程序总是意外停止。我是否正确地称之为新意图?

  

头等舱:

public class first extends Activity {


  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

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

    Button SignIn = (Button) findViewById(R.id.SignIn);
    SignIn.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
          EditText pw = (EditText) findViewById(R.id.editPasswd);
            if(pw.getText().toString().equals("123")) {                     

                 Intent intent = new Intent(first.this, second.class);
                 startActivity(intent);                                  
             }
            else {
                  Toast.makeText(getBaseContext(), "Wrong PIN" ,
                  Toast.LENGTH_LONG).show();
            }   

      }});
  }
 }
  

第二课:

public class second extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

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

    Button Button01 = (Button) findViewById(R.id.Button01);
    Button01.setOnClickListener(new OnClickListener() { 

    public void onClick(View v) {
      if(v.getId() == R.id.Button01) { 

          Intent intent = new Intent(second.this, third.class);
          startActivity(intent); 
     }} 
    });
  }
}
  

第三课:

public class third extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lock);
  }}

当我输入正确的密码时,应用程序显示消息“应用程序()已意外停止。请再试一次”。首先,我想知道我的代码是正确的。

1 个答案:

答案 0 :(得分:1)

无论您想要显示哪些活动,都必须在AndroidManifest.xml文件中对这些活动进行调整。例如,在AndroidManifest.xml文件中提及的第一,第二,第三活动