package com.lxj.lesson2_3ID19;

import com.example.lesson2_3_id19.R;
import com.lxj.other.AgeActivity;
import com.lxj.other.HeightActivity;
import com.lxj.other.SexActivity; import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent; public class MainActivity extends Activity implements OnClickListener {
private static final int REQUEST_AGE = 1;
private static final int REQUEST_HEIGHT = 2;
private static final int REQUEST_SEX = 3;
User user = new User();
TextView tvAge,tvHeight,tvSex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initView();
registerListener();
}
private void registerListener() {
tvAge.setOnClickListener(this);
tvHeight.setOnClickListener(this);
tvSex.setOnClickListener(this);
}
private void initView() {
tvAge = (TextView) findViewById(R.id.tv_age);
tvHeight = (TextView) findViewById(R.id.tv_height);
tvSex = (TextView) findViewById(R.id.tv_sex);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_age:
startActivityForResult(new Intent(this, AgeActivity.class), REQUEST_AGE);
break;
case R.id.tv_height:
startActivityForResult(new Intent(this, HeightActivity.class), REQUEST_HEIGHT);
break;
case R.id.tv_sex:
startActivityForResult(new Intent(this, SexActivity.class), REQUEST_SEX);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// 调试可见,程序中不用
Log.e("TAG", "-------------程序从" + requestCode + "返回");
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_AGE:
String age = data.getStringExtra("age");
tvAge.setText(age);
break;
case REQUEST_HEIGHT:
String height = data.getStringExtra("height");
tvHeight.setText(height);
break;
case REQUEST_SEX:
String sex = data.getStringExtra("sex");
tvSex.setText(sex);
break;
}
}else {
// 调试程序用log,代码中不需要
Log.e("TAG", "-------------程序没有任何返回");
}
}
}
package com.lxj.lesson2_3ID19;

public class User {
String age;
String height;
String sex;
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public User(String age, String height, String sex) {
super();
this.age = age;
this.height = height;
this.sex = sex;
} public User() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return "User [age=" + age + ", height=" + height + ", sex=" + sex + "]";
} }
package com.lxj.other;

import com.example.lesson2_3_id19.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView; public class AgeActivity extends Activity implements OnClickListener{
TextView aga1,age2,age3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_age);
initView();
registerListener();
}
private void registerListener() {
aga1.setOnClickListener(this);
age2.setOnClickListener(this);
age3.setOnClickListener(this);
}
private void initView() {
aga1 = (TextView) findViewById(R.id.tv_age_1);
age2 = (TextView) findViewById(R.id.tv_age_2);
age3 = (TextView) findViewById(R.id.tv_age_3);
}
@Override
public void onClick(View v) {
// 这个v代表当前所点击的视图
// instanceof:代表 左边的对象是否是右边类型的实例
if (v instanceof TextView) {
// 把v强转成TextView类型
TextView tv = (TextView) v; //带参返回的步骤
Intent intent = getIntent();
// tv.getText()中的数据返回回去
// 将返回值放进去
intent.putExtra("age", tv.getText());
// setResult();
// 请求成功
// 设置返回码和返回值
setResult(RESULT_OK, intent);
// setResult要配合finish使用
finish();
}
} }
package com.lxj.other;

import com.example.lesson2_3_id19.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView; public class HeightActivity extends Activity implements OnClickListener{
TextView tv_height_1,tv_height_2,tv_height_3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 找不到布局
// 1. 布局和代码不在一个工程
// 2. android.R
setContentView(R.layout.activity_height);
tv_height_1 = (TextView) findViewById(R.id.height_1);
tv_height_2 = (TextView) findViewById(R.id.height_2);
tv_height_3 = (TextView) findViewById(R.id.height_3); // 用this就需要实现OnClickListener
tv_height_1.setOnClickListener(this);
tv_height_2.setOnClickListener(this);
tv_height_3.setOnClickListener(this); }
@Override
public void onClick(View v) {
// 强转v成TextView
TextView tv = (TextView) v; //带参返回的步骤
Intent intent = getIntent();
intent.putExtra("height", tv.getText());
setResult(RESULT_OK, intent);
finish();
}
}
package com.lxj.other;

import com.example.lesson2_3_id19.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView; public class SexActivity extends Activity implements OnClickListener{
TextView tv_sex_1,tv_sex_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sex);
tv_sex_1 = (TextView) findViewById(R.id.sex_1);
tv_sex_2 = (TextView) findViewById(R.id.sex_2); // 实现OnClickListener
tv_sex_1.setOnClickListener(this);
tv_sex_2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
TextView tv = (TextView) v;
Intent intent = getIntent();
intent.putExtra("sex", tv.getText());
// 设置返回码返回值
setResult(RESULT_OK, intent);
finish();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="张三"
android:textSize="20dp"
android:layout_margin="5dp" /> <TextView
android:id="@+id/tv_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="年龄"
android:textSize="18dp"
android:layout_margin="10dp" /> <TextView
android:id="@+id/tv_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="身高"
android:textSize="18dp"
android:layout_margin="10dp" /> <TextView
android:id="@+id/tv_sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="性别"
android:textSize="18dp"
android:layout_margin="10dp" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/tv_age_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="18岁以下"
android:textSize="18dp" /> <TextView
android:id="@+id/tv_age_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="18—30岁"
android:textSize="18dp" /> <TextView
android:id="@+id/tv_age_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="30岁以上"
android:textSize="18dp" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/height_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="170cm以下"
android:textSize="18dp"
android:layout_margin="10dp" /> <TextView
android:id="@+id/height_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="170-180cm"
android:textSize="18dp"
android:layout_margin="10dp" /> <TextView
android:id="@+id/height_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="180cm以上"
android:textSize="18dp"
android:layout_margin="10dp" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/sex_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="男"
android:textSize="18dp" /> <TextView
android:id="@+id/sex_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="女"
android:textSize="18dp" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lesson2_3_id19"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="18" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.lxj.lesson2_3ID19.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.lxj.other.AgeActivity">
</activity>
<activity
android:name="com.lxj.other.HeightActivity">
</activity>
<activity
android:name="com.lxj.other.SexActivity">
</activity>
</application> </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. 洛谷P3385判负环——spfa

    题目:https://www.luogu.org/problemnew/show/P3385 两种方法,dfs和bfs: 一开始写的dfs,要把dis数组初值赋成0,这样从一个连着负边的点开始搜: 在 ...

  2. sql之外键变种

    多对一 : 只需设个外键 外键变种之一对一:普通外键关联的表是一对多关系,如果外键上再加上唯一索引,表就会变成一对一关系. 外键变种之多对多:

  3. c++中stl----vector

    1 vector是啥玩意 (1)可以使用下标访问个别的元素 (2)迭代器可以按照不同的方式遍历 (3)可以在容器的末尾增加或者删除元素 2 容器大小和容器的容量区别 (1)大小是元素的个数,容量是分配 ...

  4. 【Data Structure & Algorithm】字符串全排列

    字符串全排列 题目:输入一个字符串,打印出该字符串的所有排列.例如输入字符串abc,则输出由字符a.b.c所能排列出来的所有字符串abc.acb.bac.bca.cab.cba. 分析:考察对递归的理 ...

  5. POJ 3662 Telephone Lines (二分+dijkstra)

    题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...

  6. Bootstrap表格分页(一)

    最近在学习Bootstrap的分页,有一种方法用“Bootstrap-Paginator”的东西来做. 先预览一下: 为了能够局部刷新页面,我创建了一个PartialView 页面的HTML部分如下: ...

  7. Linux which 查找命令

    在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 权限管理命令: which 基础的命令 命令名称:which 命令的所在路径:/usr/bin ...

  8. CSS3 制作魔方 - 相关立体样式

    最好的实践,就是给定一个实践的目标去实践. 目标:利用 CSS3 的一些特性,绘制一个魔方,要可以玩转的那种,即上下左右每一层都可以独立旋转.效果如下: 为了完成此效果,将使用到以下相关概念和样式:坐 ...

  9. 洛谷 - P2158 - 仪仗队 - 欧拉函数

    https://www.luogu.org/problemnew/show/P2158 好像以前有个妹子收割铲也是欧拉函数. 因为格点直线上的点,dx与dy的gcd相同,画个图就觉得是欧拉函数.但是要 ...

  10. 解决 unity 生成 android apk read Resources

    http://www.cnblogs.com/solq/archive/2012/05/21/2511522.html TextAsset t = (TextAsset)Resources.Load( ...