用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);
}
}
不知道哪里出现了问题
解决方案 »
- 求大神解答关于PreferenceActivity数据读取问题!
- ViewPager中使用PagerTabStrip遇到的问题
- 如何知道一个String 是一个有效的URL 地址。
- android当中多出Jni的包,怎么回事
- Android怎样去掉其它应用用WindowManager增加的view?
- adroid 设置---快捷方式
- 让所有的通讯录的姓名以Preference形式显示出来
- android sqlite3 在adb 中执行问题
- 最新版本_adt-bundle-windows-x86_64-20140702 无法建立avd
- 双卡机器调用拨号盘拨号时怎么控制用哪张卡拨号?
- 线程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之后没有响应事件