弄了这么多天终于能跳转了,哭瞎T T

首先在在AndroidManifest.xml里配置(这个得先在src里新建一个OtherActivity.java)

  

在第一个main layout里面配置一个跳转按钮

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="打开otheractivity"
android:id="@+id/button"   //id名字记住
/>

配置第二个layout

xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">

android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="other activiy"
/>


待跳转页面的activity,与第二个layout结合.代码如下
public class OtherActivity extends Activity { 
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.other);

}

对主activity配置.点击button可以跳转到第二个页面
(会有很多问题,如果使用Eclipse的话,可以使用快捷键【Ctrl+Shift+o】 ,自动添加相应的import。)

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;


Button button = (Button)this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// 打开另一个activity,通过意图,意图作用是激活其他组件
Intent intent = new Intent();
intent.setClass(MainActivityActivity.this, OtherActivity.class);

//发送意图.将意图发送给android系统,系统根据意图来激活组件
startActivity(intent);
}
});
}

更多相关文章

  1. AndroidStuio快速发布开源项目到Jcenter/Bintray
  2. 如何配置eclipse的安卓SDK下载目录
  3. android SELinux 问题解决-如何用工具生成相关权限配置文件?
  4. Android(安卓)Studio配置百度地图开发环境
  5. Android(安卓)ijkplayer编译(支持https协议)
  6. Android(安卓)JNI打印Log
  7. Android(安卓)Day01-电话拨号器案例&Android开发流程
  8. Android(安卓)OPenCV 环境配置
  9. mac下配置android studio工具

随机推荐

  1. JS学习之 解构赋值
  2. php数据类型及变量的定义使用
  3. PHP第一课 变量命名、数据类型
  4. 第四课 box-sizing、伪类、媒体查询移动
  5. PHP基础
  6. iOS tableView右侧索引视图状态获取的方
  7. 浅谈IOS屏幕刷新ADisplayLink
  8. 详解IOS WebRTC的实现原理
  9. 详解如何使用ReactiveObjC
  10. 1.HTML上手练习 2. 预习css知识