一个关于用eclipse写的安卓两个activity相互转换的问题,程序没报错但是安装在虚拟机上以后打不开。
代码在下面:packagecom.example.ex03_099;importandroid.os.Bundle;importandroid.app.Activity;...
代码在下面:
package com.example.ex03_099;
import android.os.Bundle;import android.app.Activity;import android.content.Intent; import android.view.View; import android.widget.Button; public class EX03_099 extends Activity { private Button b1=null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.setClass(EX03_099.this, Ex03_099_01.class); startActivity(intent); EX03_099.this.finish(); } }); } }
package com.example.ex03_099;
import android.os.Bundle;import android.app.Activity;import android.content.Intent; import android.view.View; import android.widget.Button; public class Ex03_099_01 extends Activity { private Button b2=null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mylayout); b2 = (Button) findViewById(R.id.button2); b2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /* new一个Intent对象,并指定要启动的class */ Intent intent = new Intent(); intent.setClass(Ex03_099_01.this, EX03_099.class); startActivity(intent); Ex03_099_01.this.finish(); } }); } }
LogCat是这样显示的: 展开
package com.example.ex03_099;
import android.os.Bundle;import android.app.Activity;import android.content.Intent; import android.view.View; import android.widget.Button; public class EX03_099 extends Activity { private Button b1=null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.setClass(EX03_099.this, Ex03_099_01.class); startActivity(intent); EX03_099.this.finish(); } }); } }
package com.example.ex03_099;
import android.os.Bundle;import android.app.Activity;import android.content.Intent; import android.view.View; import android.widget.Button; public class Ex03_099_01 extends Activity { private Button b2=null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mylayout); b2 = (Button) findViewById(R.id.button2); b2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /* new一个Intent对象,并指定要启动的class */ Intent intent = new Intent(); intent.setClass(Ex03_099_01.this, EX03_099.class); startActivity(intent); Ex03_099_01.this.finish(); } }); } }
LogCat是这样显示的: 展开
3个回答
展开全部
你新建Activity的时候要记得注册啊,少年
追问
额 我注册了 还是没用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询