1. package com.lxj.lesson2_3ID19;
  2.  
  3. import com.example.lesson2_3_id19.R;
  4. import com.lxj.other.AgeActivity;
  5. import com.lxj.other.HeightActivity;
  6. import com.lxj.other.SexActivity;
  7.  
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.widget.TextView;
  13. import android.app.Activity;
  14. import android.content.Intent;
  15.  
  16. public class MainActivity extends Activity implements OnClickListener {
  17. private static final int REQUEST_AGE = 1;
  18. private static final int REQUEST_HEIGHT = 2;
  19. private static final int REQUEST_SEX = 3;
  20. User user = new User();
  21. TextView tvAge,tvHeight,tvSex;
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_main);
  26.  
  27. initView();
  28. registerListener();
  29. }
  30. private void registerListener() {
  31. tvAge.setOnClickListener(this);
  32. tvHeight.setOnClickListener(this);
  33. tvSex.setOnClickListener(this);
  34. }
  35. private void initView() {
  36. tvAge = (TextView) findViewById(R.id.tv_age);
  37. tvHeight = (TextView) findViewById(R.id.tv_height);
  38. tvSex = (TextView) findViewById(R.id.tv_sex);
  39. }
  40. @Override
  41. public void onClick(View v) {
  42. switch (v.getId()) {
  43. case R.id.tv_age:
  44. startActivityForResult(new Intent(this, AgeActivity.class), REQUEST_AGE);
  45. break;
  46. case R.id.tv_height:
  47. startActivityForResult(new Intent(this, HeightActivity.class), REQUEST_HEIGHT);
  48. break;
  49. case R.id.tv_sex:
  50. startActivityForResult(new Intent(this, SexActivity.class), REQUEST_SEX);
  51. break;
  52. }
  53. }
  54. @Override
  55. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  56. super.onActivityResult(requestCode, resultCode, data);
  57. // 调试可见,程序中不用
  58. Log.e("TAG", "-------------程序从" + requestCode + "返回");
  59. if (resultCode == RESULT_OK) {
  60. switch (requestCode) {
  61. case REQUEST_AGE:
  62. String age = data.getStringExtra("age");
  63. tvAge.setText(age);
  64. break;
  65. case REQUEST_HEIGHT:
  66. String height = data.getStringExtra("height");
  67. tvHeight.setText(height);
  68. break;
  69. case REQUEST_SEX:
  70. String sex = data.getStringExtra("sex");
  71. tvSex.setText(sex);
  72. break;
  73. }
  74. }else {
  75. // 调试程序用log,代码中不需要
  76. Log.e("TAG", "-------------程序没有任何返回");
  77. }
  78. }
  79. }
  1. package com.lxj.lesson2_3ID19;
  2.  
  3. public class User {
  4. String age;
  5. String height;
  6. String sex;
  7. public String getAge() {
  8. return age;
  9. }
  10. public void setAge(String age) {
  11. this.age = age;
  12. }
  13. public String getHeight() {
  14. return height;
  15. }
  16. public void setHeight(String height) {
  17. this.height = height;
  18. }
  19. public String getSex() {
  20. return sex;
  21. }
  22. public void setSex(String sex) {
  23. this.sex = sex;
  24. }
  25. public User(String age, String height, String sex) {
  26. super();
  27. this.age = age;
  28. this.height = height;
  29. this.sex = sex;
  30. }
  31.  
  32. public User() {
  33. super();
  34. // TODO Auto-generated constructor stub
  35. }
  36. @Override
  37. public String toString() {
  38. return "User [age=" + age + ", height=" + height + ", sex=" + sex + "]";
  39. }
  40.  
  41. }
  1. package com.lxj.other;
  2.  
  3. import com.example.lesson2_3_id19.R;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.TextView;
  11.  
  12. public class AgeActivity extends Activity implements OnClickListener{
  13. TextView aga1,age2,age3;
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_age);
  18. initView();
  19. registerListener();
  20. }
  21. private void registerListener() {
  22. aga1.setOnClickListener(this);
  23. age2.setOnClickListener(this);
  24. age3.setOnClickListener(this);
  25. }
  26. private void initView() {
  27. aga1 = (TextView) findViewById(R.id.tv_age_1);
  28. age2 = (TextView) findViewById(R.id.tv_age_2);
  29. age3 = (TextView) findViewById(R.id.tv_age_3);
  30. }
  31. @Override
  32. public void onClick(View v) {
  33. // 这个v代表当前所点击的视图
  34. // instanceof:代表 左边的对象是否是右边类型的实例
  35. if (v instanceof TextView) {
  36. // 把v强转成TextView类型
  37. TextView tv = (TextView) v;
  38.  
  39. //带参返回的步骤
  40. Intent intent = getIntent();
  41. // tv.getText()中的数据返回回去
  42. // 将返回值放进去
  43. intent.putExtra("age", tv.getText());
  44. // setResult();
  45. // 请求成功
  46. // 设置返回码和返回值
  47. setResult(RESULT_OK, intent);
  48. // setResult要配合finish使用
  49. finish();
  50. }
  51. }
  52.  
  53. }
  1. package com.lxj.other;
  2.  
  3. import com.example.lesson2_3_id19.R;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.TextView;
  11.  
  12. public class HeightActivity extends Activity implements OnClickListener{
  13. TextView tv_height_1,tv_height_2,tv_height_3;
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. // 找不到布局
  18. // 1. 布局和代码不在一个工程
  19. // 2. android.R
  20. setContentView(R.layout.activity_height);
  21. tv_height_1 = (TextView) findViewById(R.id.height_1);
  22. tv_height_2 = (TextView) findViewById(R.id.height_2);
  23. tv_height_3 = (TextView) findViewById(R.id.height_3);
  24.  
  25. // 用this就需要实现OnClickListener
  26. tv_height_1.setOnClickListener(this);
  27. tv_height_2.setOnClickListener(this);
  28. tv_height_3.setOnClickListener(this);
  29.  
  30. }
  31. @Override
  32. public void onClick(View v) {
  33. // 强转v成TextView
  34. TextView tv = (TextView) v;
  35.  
  36. //带参返回的步骤
  37. Intent intent = getIntent();
  38. intent.putExtra("height", tv.getText());
  39. setResult(RESULT_OK, intent);
  40. finish();
  41. }
  42. }
  1. package com.lxj.other;
  2.  
  3. import com.example.lesson2_3_id19.R;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.TextView;
  11.  
  12. public class SexActivity extends Activity implements OnClickListener{
  13. TextView tv_sex_1,tv_sex_2;
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_sex);
  18. tv_sex_1 = (TextView) findViewById(R.id.sex_1);
  19. tv_sex_2 = (TextView) findViewById(R.id.sex_2);
  20.  
  21. // 实现OnClickListener
  22. tv_sex_1.setOnClickListener(this);
  23. tv_sex_2.setOnClickListener(this);
  24. }
  25. @Override
  26. public void onClick(View v) {
  27. TextView tv = (TextView) v;
  28. Intent intent = getIntent();
  29. intent.putExtra("sex", tv.getText());
  30. // 设置返回码返回值
  31. setResult(RESULT_OK, intent);
  32. finish();
  33. }
  34. }
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical" >
  5.  
  6. <TextView
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:gravity="center"
  10. android:text="张三"
  11. android:textSize="20dp"
  12. android:layout_margin="5dp" />
  13.  
  14. <TextView
  15. android:id="@+id/tv_age"
  16. android:layout_width="match_parent"
  17. android:layout_height="wrap_content"
  18. android:gravity="center"
  19. android:text="年龄"
  20. android:textSize="18dp"
  21. android:layout_margin="10dp" />
  22.  
  23. <TextView
  24. android:id="@+id/tv_height"
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:gravity="center"
  28. android:text="身高"
  29. android:textSize="18dp"
  30. android:layout_margin="10dp" />
  31.  
  32. <TextView
  33. android:id="@+id/tv_sex"
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:gravity="center"
  37. android:text="性别"
  38. android:textSize="18dp"
  39. android:layout_margin="10dp" />
  40.  
  41. </LinearLayout>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <TextView
  8. android:id="@+id/tv_age_1"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:layout_margin="10dp"
  12. android:gravity="center"
  13. android:text="18岁以下"
  14. android:textSize="18dp" />
  15.  
  16. <TextView
  17. android:id="@+id/tv_age_2"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_margin="10dp"
  21. android:gravity="center"
  22. android:text="18—30岁"
  23. android:textSize="18dp" />
  24.  
  25. <TextView
  26. android:id="@+id/tv_age_3"
  27. android:layout_width="match_parent"
  28. android:layout_height="wrap_content"
  29. android:layout_margin="10dp"
  30. android:gravity="center"
  31. android:text="30岁以上"
  32. android:textSize="18dp" />
  33.  
  34. </LinearLayout>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <TextView
  8. android:id="@+id/height_1"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:gravity="center"
  12. android:text="170cm以下"
  13. android:textSize="18dp"
  14. android:layout_margin="10dp" />
  15.  
  16. <TextView
  17. android:id="@+id/height_2"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:gravity="center"
  21. android:text="170-180cm"
  22. android:textSize="18dp"
  23. android:layout_margin="10dp" />
  24.  
  25. <TextView
  26. android:id="@+id/height_3"
  27. android:layout_width="match_parent"
  28. android:layout_height="wrap_content"
  29. android:gravity="center"
  30. android:text="180cm以上"
  31. android:textSize="18dp"
  32. android:layout_margin="10dp" />
  33.  
  34. </LinearLayout>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <TextView
  8. android:id="@+id/sex_1"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:layout_margin="10dp"
  12. android:gravity="center"
  13. android:text="男"
  14. android:textSize="18dp" />
  15.  
  16. <TextView
  17. android:id="@+id/sex_2"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_margin="10dp"
  21. android:gravity="center"
  22. android:text="女"
  23. android:textSize="18dp" />
  24.  
  25. </LinearLayout>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.example.lesson2_3_id19"
  4. android:versionCode="1"
  5. android:versionName="1.0" >
  6.  
  7. <uses-sdk
  8. android:minSdkVersion="15"
  9. android:targetSdkVersion="18" />
  10.  
  11. <application
  12. android:allowBackup="true"
  13. android:icon="@drawable/ic_launcher"
  14. android:label="@string/app_name"
  15. android:theme="@style/AppTheme" >
  16. <activity
  17. android:name="com.lxj.lesson2_3ID19.MainActivity"
  18. android:label="@string/app_name" >
  19. <intent-filter>
  20. <action android:name="android.intent.action.MAIN" />
  21.  
  22. <category android:name="android.intent.category.LAUNCHER" />
  23. </intent-filter>
  24. </activity>
  25. <activity
  26. android:name="com.lxj.other.AgeActivity">
  27. </activity>
  28. <activity
  29. android:name="com.lxj.other.HeightActivity">
  30. </activity>
  31. <activity
  32. android:name="com.lxj.other.SexActivity">
  33. </activity>
  34. </application>
  35.  
  36. </manifest>

android布局带参返回的更多相关文章

  1. mui自定义事件带参返回mui.back()

    父页面添加自定义监听事件:(e.detail.xxx) window.addEventListener('doit', function(e){ //获取参数值 var imagePath = e.d ...

  2. IE浏览器new Date()带参返回NaN解决方法

    var start = '2016-01-01 12:12:12'; var date = new Date(start); 得到的时间为NaN: 解决方法: 1.自定义方法 自定义一个NewDate ...

  3. IE浏览器(js)new Date()带参返回NaN解决方法

    function myNewDate(str) { if(!str){ return 0; } arr=str.split(" "); d=arr[0].split("- ...

  4. Android--Intent组件带参传递与返回

    Android 是 单例模式: 表示 application 唯一的.每个应用被启动的时候,其实是 application 被创建. Context 上下文: context 是 Applicatio ...

  5. 066 01 Android 零基础入门 01 Java基础语法 08 Java方法 02 带参有返回值方法

    066 01 Android 零基础入门 01 Java基础语法 08 Java方法 04 带参有返回值方法 本文知识点:带参有返回值方法 说明:因为时间紧张,本人写博客过程中只是对知识点的关键步骤进 ...

  6. 065 01 Android 零基础入门 01 Java基础语法 08 Java方法 02 带参无返回值方法

    065 01 Android 零基础入门 01 Java基础语法 08 Java方法 03 带参无返回值方法 本文知识点:带参无返回值方法 说明:因为时间紧张,本人写博客过程中只是对知识点的关键步骤进 ...

  7. 慕课网-Java入门第一季-7-5 Java 中带参无返回值方法的使用

    public class HelloWorld { public static void main(String[] args) { // 创建对象,对象名为hello HelloWorld hell ...

  8. Java 中带参带返回值方法的使用

    如果方法既包含参数,又带有返回值,我们称为带参带返回值的方法. 例如:下面的代码,定义了一个 show 方法,带有一个参数 name ,方法执行后返回一个 String 类型的结果 调用带参带返回值的 ...

  9. Java 中带参无返回值方法的使用

    有时方法的执行需要依赖于某些条件,换句话说,要想通过方法完成特定的功能,需要为其提供额外的信息才行.例如,现实生活中电饭锅可以实现“煮饭”的功能,但前提是我们必须提供食材,如果我们什么都不提供,那就真 ...

随机推荐

  1. AtCoder Grand Contest 006 C:Rabbit Exercise

    题目传送门:https://agc006.contest.atcoder.jp/tasks/agc006_c 题目翻译 数轴上有\(N\)只兔子,从\(1\)到\(N\)编号,每只兔子初始位置是\(x ...

  2. C# HTML解析工具HtmlAgilityPack使用实例(一)

    一.生成HTML字符串 //生成DOM字符串结构 HtmlNode container = HtmlNode.CreateNode("<div />"); HtmlNo ...

  3. Ubuntu 安装Guake

    一款代替终端的软件, 只需按F12就可以调出终端, 再按就消失, 附上Github链接. https://github.com/Guake/guake 一开始没安装上去, 后来成功, 现在用着还不错, ...

  4. XAMPP打不开Apache服务的解决办法

    XAMPP打不开Apache服务的解决办法 不用修改设置,应该是80端口被占用了,直接先IIS的网站给停了就OK

  5. struts2注解的作用

    Struts2注解 1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包 必须导入struts2-convention-plugin-2.3.15.jar包, ...

  6. Fitnesse 之 Script Table

    在表中每一行代表一个执行脚本. 第一行中的Script关键字表明表格类型,后面紧跟着类名(Fixture)和构造函数中的参数.在一个测试页中如果没有再指定其它Fixture,将一直沿用上一个Fixtu ...

  7. C++11 并发编程基础(一):并发、并行与C++多线程

    正文 C++11标准在标准库中为多线程提供了组件,这意味着使用C++编写与平台无关的多线程程序成为可能,而C++程序的可移植性也得到了有力的保证.另外,并发编程可提高应用的性能,这对对性能锱铢必较的C ...

  8. unity模型法线反转问题

    fbx模型导入unity正常 但只要绑了骨骼,在3dmax中正常,进入unity就法线反转 原因是3dmax中模型用到复制和镜像的导出需要多一步处理 1重置变换 2反转法线 按顺序进行这两个,在绑定模 ...

  9. Unity2d 骨骼动画1:介绍

    http://bbs.9ria.com/thread-401613-1-1.html by Orlando Pereira and PedroPereira3 days ago2 Comments 在 ...

  10. 如何解决启动Error:com.intellij.util.indexing.StorageException问题?

    启动tomcat时idea出现如下错误: Error:com.intellij.util.indexing.StorageException: com.intellij.util.indexing.S ...