android 页面跳转,数据回传
package com.example.firstpg.firstpg; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;
import android.content.Intent; public class FirstlayoutActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.firstlayout);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_firstlayout, menu);
return true ;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
switch (id)
{
case R.id.add_item:
Toast.makeText(this,"大海啊大海",Toast.LENGTH_SHORT).show();
break;
case R.id.edit_item:
Intent intent=new Intent(FirstlayoutActivity.this,SecondlayoutActivity.class);
startActivity(intent);
break;
case R.id.del_item:
Intent intent2=new Intent(FirstlayoutActivity.this,SecondlayoutActivity.class);
intent2.putExtra("data1", "你好1");
startActivityForResult(intent2,1);
break;
default:
finish();
} return super.onOptionsItemSelected(item);
}
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
String retrundata = data.getStringExtra("data2");
Log.d("data2", retrundata);
}
break;
}
}
}
package com.example.firstpg.firstpg; import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button; public class SecondlayoutActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondlayout);
Intent intent=getIntent();
String data=intent.getStringExtra("data1");
Log.d("data1", data);
Button button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intert=new Intent();
intert.putExtra("data2","你好2");
setResult(RESULT_OK,intert);
finish();
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_secondlayout, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
}
}
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".FirstlayoutActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="195dp" /> </RelativeLayout>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.firstpg.firstpg.SecondlayoutActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" /> </RelativeLayout>
menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".FirstlayoutActivity">
<item android:id="@+id/add_item" android:title="添加" />
<item android:id="@+id/edit_item" android:title="修改" />
<item android:id="@+id/del_item" android:title="回传数据测试" />
<item android:id="@+id/return_item" android:title="退出" />
</menu>
android 页面跳转,数据回传的更多相关文章
- Android页面之间进行数据回传
要求:页面1跳转到页面2,页面2再返回页面1同时返回数据 页面1添加如下代码: Intent intent = new Intent(); intent.setClass(页面1.this, 页面2. ...
- Android 页面跳转之生命周期调用顺序问题
Android Activity 常用技巧 Android Activity 启动模式和任务栈 Android 页面跳转之生命周期调用顺序问题 一.页面跳转逻辑分析 1.1 跳转逻辑分析 Androi ...
- 【swift学习笔记】二.页面转跳数据回传
上一篇我们介绍了页面转跳:[swift学习笔记]一.页面转跳的条件判断和传值 这一篇说一下如何把数据回传回父页面,如下图所示,这个例子很简单,只是把传过去的数据加上了"回传"两个字 ...
- Android first --- 页面跳转及数据传递
页面跳转即数据传递 创建第二个界面Acivity *需要在清单文件中添加配置一个Actuvity标签 标签中如果带有这个子节点,则会在Android中添加一个快捷图标 <intent-filte ...
- Android 完美解决bundle实现页面跳转并保留之前数据+传值
1.前言 前言: 昨天碰到了一个问题,我想实现页面跳转,采用了Bundle之后,再回到原来的页面,发现数据也没有了, 而且一直报错,网上查找了很多资料,发现要用一个startActivityForRe ...
- Android成长日记-使用Intent实现页面跳转
Intent:可以理解为信使(意图),由Intent来协助完成Android各个组件之间的通讯 Intent实现页面之间的跳转 1->startActivity(intent) 2->st ...
- Android实现页面跳转、ListView及其事件
Android实现页面跳转.ListView及其事件 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 进入主页面后,使用ListView实现特 ...
- Android+Jquery Mobile学习系列(4)-页面跳转及参数传递
关于页面转场,这个必须得专门列出来说明一下,因为Jquery Mobile与普通的Web发开有一些区别,这个对于新手如果不了解的话,就会钻到死胡同.撸主前段时间就是很急躁地上手开发程序,结果在页面转场 ...
- Android中实现activity的页面跳转并传值
一个Android应用程序很少会只有一个Activity对象,如何在多个Activity之间进行跳转,而且能够互相传值是一个很基本的要求. 本次我们就讲一下,Android中页面跳转以及传值的几种方式 ...
随机推荐
- Infobright存储引擎的特点
Infobright的优点: (1)高压缩比率 (2)快速响应复杂的分析查询语句 (3)随着数据库的逐渐增大,查询和装载性能基本保持稳定 (4)没有特殊的数据仓库模型(比如星状模型.雪花模型)要求 ( ...
- javascript学习第一课
1.基本知识: 1.1 词法结构 1.1.1 字符集 javascript程序是用Unicode字符集编写的. 1.1.2 区分大小写 javascript是区分大小写的语言.也即是关键字.变量.函数 ...
- [原]Jenkins(一)---我理解的jenkins是这样的
/** * lihaibo * 文章内容都是根据自己工作情况实践得出. *版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/5330 ...
- SQL分页查询结果不一致
今天遇到了SQL分页查询结果不一致的情况,一看代码,原来是没加排序查询!!分页查询最好加排序,且以唯一性高的字段进行排序,如ID,时间等,以保持每页查询结果的准确! PS:又帮别人擦屁股!!
- 深入浅出Symfony2 - 如何提高网站响应速度 [转]
简介 Symfony2是一个基于PHP语言的Web开发框架,有着开发速度快.性能高等特点.但Symfony2的学习曲线也比较陡峭,没有经验的初学者往往需要一些练习才能掌握其特性.相对其他框架,Symf ...
- Jade之Interpolation
Interpolation jade为不同的需求提供了一些特殊的操作符.详见Github = 将右边的值赋予左边,或者替换为右边变量的值. //- 赋值,js格式即可. - var title = & ...
- Winpcap构建用户级网桥
Winpcap构建网桥 根据winpcap sdk中的user-level-bridge用户级网桥 |机器1 | |机器2 | | ...
- line-height,vertical-align及图片居中对齐问题根源解析
关于图片居中对齐的问题,进入前端行业虽然有一段时间了,以为自己懂了,可是实际上还是一知半解,找了一些博客来看了一下,但是感觉讲的有点碎,看完还是一知半解. 查阅了一下<css权威指南>,结 ...
- 国内CDN公共库
CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用.与将JS库存放在服务器单机上相比,CDN公共库更加稳定.高速.一般的CDN公共库都会包含全球所有最流行的开源JavaScrip ...
- 3.SRS文档
1.功能需求 本程序的使用者为局域网用户.程序实现的主要功能是局域网的常见格式的文件的传 输.其用例图如图1.本程序可通过可视化操作界面实现一对多的文件传输. 1.1模块分析 为实现局域网文件传输, ...