Intent--接收返回数据
来源:互联网 发布:圈子圈套 知乎 编辑:程序博客网 时间:2024/05/01 18:39
package org.lxh.demo;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class Receive extends Activity {private TextView show = null ;// 文本显示组件private Button retbut = null ;// 按钮组件@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.receive_main);// 调用默认布局管理器this.show = (TextView) super.findViewById(R.id.show) ;// 取得组件this.retbut = (Button) super.findViewById(R.id.retbut) ;// 取得组件Intent it = super.getIntent() ;// 取得启动此程序的IntentString info = it.getStringExtra("myinfo") ;// 取得设置的附加信息this.show.setText(info) ;// 设置文本显示信息this.retbut.setOnClickListener(new OnClickListenerImpl()) ;// 设置监听}private class OnClickListenerImpl implements OnClickListener {@Overridepublic void onClick(View view) {Receive.this.getIntent().putExtra("retmsg", "老师:李兴华") ;// 返回信息// 设置返回数据的状态,RESULT_OK与Send.java中的onActivityResult()里判断的对应Receive.this.setResult(RESULT_OK, Receive.this.getIntent()) ;Receive.this.finish() ;// 结束Intent}}}
package org.lxh.demo;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class Send extends Activity {private Button mybut = null ;// 按钮组件private TextView msg = null ;// 文本组件@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.send_main);// 默认布局管理器this.mybut = (Button) super.findViewById(R.id.mybut) ;// 取得组件this.msg = (TextView) super.findViewById(R.id.msg) ;// 取得组件this.mybut.setOnClickListener(new OnClickListenerImpl());// 定义单击事件}private class OnClickListenerImpl implements OnClickListener {@Overridepublic void onClick(View view) {Intent it = new Intent(Send.this, Receive.class);// 实例化Intentit.putExtra("myinfo", "北京魔乐科技软件学院(www.mldnjava.cn)") ;// 设置附加信息Send.this.startActivityForResult(it, 1);// 启动Activity}}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {switch (resultCode) {// 判断操作类型case RESULT_OK:// 成功操作msg.setText("返回的内容是:" + data.getStringExtra("retmsg"));break;case RESULT_CANCELED:// 取消操作msg.setText("操作取消。");break ;default:break;}}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/MyLayout"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:id="@+id/show"android:layout_width="wrap_content"android:layout_height="wrap_content"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/MyLayout"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><Buttonandroid:id="@+id/mybut"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按我将跳转到另一个Activity程序"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="org.lxh.demo" android:versionCode="1" android:versionName="1.0"><uses-sdk android:minSdkVersion="10" /><application android:icon="@drawable/icon" android:label="@string/app_title"><activity android:name="Send" android:label="@string/app_title"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name="Receive" android:label="@string/receive_name" /></application></manifest>
0 0
- Intent--接收返回数据
- Android实现intent跳转界面传递数据(2)——onActivityResult方法接收返回值
- Intent传递值,接收返回值
- bundle及intent传递接收数据
- intent 数据传递和返回数据
- Intent传递数据 (得到返回数据)
- 通过 Intent传递数据,并返回结果
- android intent传递数据,返回函数
- 使用Intent传递数据之返回结果
- Android intent返回数据给上一个活动
- 返回数据给上一个活动(intent)
- Intent返回数据给上一个活动<IntentputExtra>
- Intent返回数据给上一个活动
- 客户端接收不到servlet返回数据
- 接收从其他app返回的数据
- EasyUI.grid接收Struts2返回数据
- SpringMVC接收和返回JSON数据
- jQuery的Ajax接收java返回数据
- @Repository、@Service、@Controller 和 @Component
- Centos/Redhat 下显示中文
- Android Handler的使用
- android图形系统详解六:View layer
- Tizen App大赛公布获奖名单,“画app吧(www.drawapp8.com)”榜上有名!
- Intent--接收返回数据
- iOS 中设计模式
- 小希的迷宫
- android坐标
- 文件夹备份和数据库备份
- hdu 2544 最短路
- android图形系统详解五:Android绘制模式
- pl/sql developer 编码格式设置
- Android WebApp 開發教學 (1) – HTML5 WebView 行動應用