android,activity跳转问题,eclipse可以编译运行,但在模拟器上按下按钮时总出现activity_02错误无法跳转
packageshen.activity_02;importshen.activity_02.R;importandroid.os.Bundle;importandroi...
package shen.activity_02;
import shen.activity_02.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton=(Button)findViewById(R.id.myButton);
TextView myTextView=(TextView)findViewById(R.id.myTextView);
myTextView.setText("我的第一个textview");
myButton.setText("我的第一个Button");
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements OnClickListener{
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this,Activity_02.class);
MainActivity.this.startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
} 展开
import shen.activity_02.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton=(Button)findViewById(R.id.myButton);
TextView myTextView=(TextView)findViewById(R.id.myTextView);
myTextView.setText("我的第一个textview");
myButton.setText("我的第一个Button");
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements OnClickListener{
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this,Activity_02.class);
MainActivity.this.startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询