用android编写的两个activity事件之间的转换问题,用到按钮响应事件,用接口 implements OnClickListener,调试没有错误,在模拟器下面运行的时候点击按钮出现com.activity02 stoped 问题
class myButtonListener implements OnClickListener{
public void onClick(View v){
Intent intent=new Intent();
intent.putExtra("testIntent", "123");
intent.setClass(activity02.this,otherActivity.class);
activity02.this.startActivity(intent);
}
}
不知道哪里出现了问题
class myButtonListener implements OnClickListener{
public void onClick(View v){
Intent intent=new Intent();
intent.putExtra("testIntent", "123");
intent.setClass(activity02.this,otherActivity.class);
activity02.this.startActivity(intent);
}
}
不知道哪里出现了问题
解决方案 »
- APK为何下载后变成了HTML或用浏览器打开
- 【问】关于android应用程序名字的问题
- 如何使程序默认的发送短信,而不需要调用发短信的程序
- android学习hellojni阶段的一个低级问题,问问大拿们
- 请问在android系统中如何用Socket发送一个结构体,并且和VC程序互相解析结构体
- 有些软件关闭了过会又自动运行了,怎么实现的啊?
- 跪求android1.5 版本googlemarket/gmail.APK
- 安卓里连接SQL数据库超时问题,找高手!!!
- 请问类似于Google now、必应、绿色守护等,可以通过虚拟home键上滑启动或进行操作是如何实现的。
- Android studio 的onclick" ",引号里要怎么写变换颜色写changeColor,有红线
- 线程wait, notify使用错误java.lang.IllegalMonitorStateException
- 手机控制家用电饭锅系统设计思路
myButton.setOnClickListener(new OnClickListener(){
Intent intent=new Intent();
intent.setClass(this,otherActivity.class);
startActivity(intent);
);
btn.setOnClickListener(new myButtonListener());如果正确的话!
那肯定是启动的另一个Activity里面出了问题!otherActivity? AndroidMainfest.xml里面注册没有?!otherActivity里的onCreate()函数里数据接收是否正确!Intent intent=getIntent();
String str=intent.getExtra("testIntent");
....楼主看看吧!
class myButtonListener implements OnClickListener{
public void onClick(View v){
if (v.equals(button)){//btn是你的按钮对象
Intent intent=new Intent();
intent.putExtra("testIntent", "123");
intent.setClass(activity02.this,otherActivity.class);
activity02.this.startActivity(intent);
}
}
}
在AndroidManifest.xml有没注册被打开的Activity,没注册会就打开会异常
<activity android:name="otherActivity"></activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.activity02"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".activity02"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.otherActivity" android:label="@string/other">
</activity>
</application>
</manifest>
Activity02文件
package com.activity02;import android.app.Activity;
import android.content.Intent;import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class activity02 extends Activity {
private Button myButton=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton=(Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new myButtonListener());
}
class myButtonListener implements OnClickListener{
public void onClick(View v){
if(v.equals(myButton)){
Intent intent=new Intent();
intent.putExtra("testIntent", "123");
intent.setClass(activity02.this,otherActivity.class);
activity02.this.startActivity(intent);
/*Uri uri=Uri.parse("Smsto://0800000123");
Intent intent=new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body", "The SMS text");
startActivity(intent);*/
}
}
}
}
otherActivity文件
package com.activity02;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;public class otherActivity extends Activity{
private TextView myTextView=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent=getIntent();
String value=intent.getStringExtra("testIntent");
myTextView=(TextView)findViewById(R.id.myTextView);
myTextView.setText(value);
}
}出现的异常
点击myButton之后没有响应事件