定义一个按钮,当点击的时候跳转到另一个activity的界面

1.新建第二个activity

2.在第二个Java源码处继承第一个activity,导入

3.在source中复写Oncreat方法

4.新建xml文件

5.在manifest中注册第二个activity

第一个activity的xml文件,定义了一个button

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.s02_e01_activity.MainActivity" > <Button
android:id="@+id/buttonid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="获取第二个Activity"/> </RelativeLayout>

接着为button绑定了监听器,第一个activity的源码

kage com.example.s02_e01_activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends ActionBarActivity { private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); button =(Button)findViewById(R.id.buttonid); ButtonListener listener=new ButtonListener();
button.setOnClickListener(listener);
} class ButtonListener implements OnClickListener{ @Override
public void onClick(View v) { Intent intent=new Intent();
intent.setClass(MainActivity.this, SeconedActivity.class);
startActivity(intent);
} } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

接着新建第二个activity的源码文件

package com.example.s02_e01_activity;

import android.app.Activity;
import android.os.Bundle; public class SeconedActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seconed);
} }

第二个的activity的xml我定义了一个textview

    <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="第二个Activity"/>

打开Android.manifest.xml文件,开始第五步,如下定义第二个activity的name和label

<activity
android:name="com.example.s02_e01_activity.SeconedActivity"
android:label="SecondActivity"> </activity>

由一个activity跳转到另一个activity的更多相关文章

  1. 【原创】Android 从一个Activity跳转到另外一个Activity

    Android四大组件activity使用,实现两个activity之间的跳转 基本流程:创建两个activity-将其中一个activity中组件作为事件源-通过组件事件的处理借助intent对象实 ...

  2. Android组件系列----当前Activity跳转到另一个Activity的详细过程

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  3. 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)

    即:android FragmentTransaction.replace的用法介绍 Fragment的生命周期和它的宿主Activity密切相关,几乎和宿主Activity的生命周期一致,他们之间最 ...

  4. Android从一个Fragment跳转到另一个Fragment后原来的组件不消失

    问题描述 Activity上放置了一个Fragment,Fragment上有按钮,点了按钮后,应该跳转到另一个Fragment, but 原来的Fragment的按钮不会消失,新的Fragment不是 ...

  5. struts2 从一个action跳转到另一个action的struts.xml文件的配置

    解释: 想要用<result>跳转到另一个action,原来的配置代码是: <action name="insertDept" class="strut ...

  6. 基于jquery的从一个页面跳转到另一个页面的指定位置的实现代码

    比如 想跳到 mao.aspx 的页面 的div id="s" 的位置 那么 只用<a href="mao.aspx#s"> 就可实现跳转到指定位置 ...

  7. android 如何从activity跳转到另一个activity下指定的fragment

    思路: 跳转到目标fragment所在的activity,并传递一个flag,来确定要到哪个fragment,根据该flag判断后,跳转到指定的fragment即可. 代码: 当前界面: intent ...

  8. 从一个App跳转到另一个App

    在跳入App的info中配置Bundle identifier 在跳入App的info中配置URL Schemes 在另一个应用程序中按照上边的操作添加openURL并运行,就可以跳转了 调用open ...

  9. jsp中点击一个图片跳转到另一个页面的方法

    1.这是jsp页面中的关于图片的那段代码 <img src="images/tj1.png " id="tj1"></img> 2.跳转 ...

随机推荐

  1. ES6入门系列一(基础)

    1.let命令 Tips: 块级作用域(只在当前块中有效) 不会变量提升(必须先申明在使用) 让变量独占该块,不再受外部影响 不允许重复声明 总之:let更像我们熟知的静态语言的的变量声明指令 ES6 ...

  2. 关于全局唯一ID生成方法

    引:最近业务开发过程中需要涉及到全局唯一ID生成.之前零零总总的收集过一些相关资料,特此整理以便后用 本博客已经迁移至:http://cenalulu.github.io/ 本篇博文已经迁移,阅读全文 ...

  3. iOS-文字自适应

    1.自动改变Label的宽和高 - (void)createLabel1 { UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero]; ...

  4. SQL Server中的事务日志管理(1/9):事务日志概况

    当一切正常时,没有必要特别留意什么是事务日志,它是如何工作的.你只要确保每个数据库都有正确的备份.当出现问题时,事务日志的理解对于采取修正操作是重要的,尤其在需要紧急恢复数据库到指定点时.这系列文章会 ...

  5. ASP.NET MVC和WebForm 轻松实现前端和后端的双重验证 jquery.validate+ValidationSugar

    上次不足的改进 可能上一个贴子给大家带来很多误解,所以我这次把DEMO完善了两个版本 [ASP.NET WEBFROM]和[ ASP.NET MVC] 修改了一些BUG,并且修改了一些细了 在上个贴子 ...

  6. 开源一个基于天天团购的团购app

    可能大家都知道天天团购开源系统,一个做团购的开源项目很赞,前些日子做了基于天天团购系统做的团购客户端和移动端服务器!源代码放出,有了解的可以看看,希望收益! 先说服务器:app的服务器,基于天天团购的 ...

  7. Spring基础—— SpEL

    一.SpEL:Spring 表达式语言,在使用的时候类似于 EL 表达式,但是需要注意的是,SpEL 使用在 Spring Config 文件中. 二.格式:使用 #{} 作为界定符,所有在大括号中的 ...

  8. 重构第7天 重命名(Rename )

    理解:重命名就是把一些函数.字段.类.参数的名称 重命名为易于理解,最好是和自身的意义相同的名称.这样更易于理解,也可以减少大量的注释,名字即含义. 详解: 这个重构方法是我经常也是最常用的一种.我们 ...

  9. 使用.NET统计文件夹中文件总数

    软件下载: http://hovertree.com/h/bjaf/hwqtjwjs.htm 截图: 使用方法:点击按钮,选择文件夹,就可以显示文件夹中包含的文件总数. 这个项目包含在HoverTre ...

  10. LeetCode131:Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...