我看过活动之间切换的每个示例,我总是得到相同的结果。应用程序炸弹。在按钮点击时打开一个新的活动
至于我可以告诉你,如果有填充布局的内容,然后才能切换到另一个布局,必须“链接”到Java文件这反过来将打开的setContentView(java类R.layout.whatever);
当我尝试这样做时,就像我说我的应用程序炸弹一样。我的代码如下: -
从Java类: -
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
Button next = (Button) findViewById(R.id.goesnews);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), ac2.class);
startActivityForResult(myIntent, 0);
}
});
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
到Java文件(AC2)
public class ac2 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}}
谁能帮助在这里?
什么是错误登录。你有没有声明清单中的活动? – stinepike
使用startActivity(myIntent);,你可以(应该)使用getApplicationContext();而不是view.getContext();还要确保你已经在androidmanifest.xml中声明了你的活动,如 –
logcat错误日志将有所帮助 – drunkenRabbit