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中页面跳转以及传值的几种方式 ...
随机推荐
- android studio小技巧
1. 为了防止乱码,请将 android studio 右下角编码设置成 UTF-8 2. Ctri + Q 查看api 3 Ctri + Shift +U 大小写互换 4 Ctrl + Alt + ...
- Python学习笔记第七天(列表解析)
列表解析: 根据已有列表,高效生成列表的方式,它的执行效率要快很多,比for循环的速度要快很多 示例如下: 生成器表达式 生成器表达式并不真正创建数字列表,而是返回一个生成器对象,此对象在每次计算出一 ...
- QEMU命令创建KVM Guest(bridge桥接)
1. Check QEMU version [root@pqsfc018 ~]# /usr/bin/qemu-system-x86_64 -version QEMU emulator version ...
- EasyUI 添加tab页(iframe方式)(转)
function addTab(title, href,icon){ var tt = $('#tabs'); if (tt.tabs('exists', title)){//如果tab已经存在,则选 ...
- SSE:服务器发送事件,使用长链接进行通讯
概述 传统的网页都是浏览器向服务器“查询”数据,但是很多场合,最有效的方式是服务器向浏览器“发送”数据.比如,每当收到新的电子邮件,服务器就向浏览器发送一个“通知”,这要比浏览器按时向服务器查询(po ...
- 【Java学习笔记】Map
Map: 一次添加一对元素,也称为双列集合. 而Collection,一次添加一个元素,称为单列集合. 常用方法: 1.添加 value put(key,value); 返回前一个与k ...
- Jungle Roads
Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...
- 使用my exclipse对数据库进行操作(2)
二.增加 public static void main(String[] args) { //TODO Auto-generated method stub //4.用户输入需要添加的项目 ...
- SWAP空间不足,如何进行添加
交换分区值过小,可以有两种方法来增加swap分区,一种是将新的分区来作为swap,另一种是在磁盘中创建一个大的文件来作swap. 我们以文件扩展swap [root@xuegod63 ~]# cd / ...
- kettle etl
使用注意点 1 如果服务器资源有限的话,尽量少开任务窗口,但是要有容错机制,可以分为按天按分钟 2 如果不想写较长的sql可以用detail来启动 3 在设置每天提交的条数时,如果数据很少,而设置值很 ...