我这个人喜欢直接上代码,在代码中说明更方便,更直接。

首先在.xml中设置一个button按钮,和一个EditText框,并分别做好id号。

这里我以籍贯测试对象。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_text1a1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
    <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/City"
android:text="籍贯"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editTextCity"
/> </LinearLayout> 在.java中,将上面的id进行注册,初始化。
之后设置button的点击事件,intent为跳转方法
public class text1A1 extends AppCompatActivity {
private Button City;
private EditText editTextCity; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text1a1);
init();
City.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(text1A1.this,text1A2.class);
startActivityForResult(intent,0); }
});
} 使用onActivityResult方法,对值的调用并返回,这里我设置“giguan”为值的接口返回
 protected void onActivityResult(int A1,int A2,Intent data){
super.onActivityResult(A1,A2,data);
if (A1 == 0 && A2 ==0);
Bundle extras=data.getExtras();
String giguan =extras.getString("giguan");
editTextCity.setText(giguan); } private void init() {
City=(Button)findViewById(R.id.City);
editTextCity=(EditText)findViewById(R.id.editTextCity);
}
} 新建textA2,在textA2的.xml表中建立ListView控件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_text1_a2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"> </ListView> </LinearLayout> 在textA2.java表中,依然注册控件,初始化。对应前面的接口,创建数据
public class text1A2 extends AppCompatActivity {
private ListView listView;
private String[] giguan={"非洲","欧洲","亚洲"}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text1_a2);
init();
ArrayAdapter adapter =new ArrayAdapter(text1A2.this,
android.R.layout.simple_list_item_1,giguan);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent =getIntent();
Bundle bundle =new Bundle();
bundle.putString("giguan",giguan[position]);
intent.putExtras(bundle);
text1A2.this.setResult(0,intent);
text1A2.this.finish(); }
});
} private void init() {
listView=(ListView)findViewById(R.id.listView);
}
}

 
 
 

Android studio关于点击事件后的页面跳转,选择完成后返回(onActivityResult)的更多相关文章

  1. android 学习第一天 了解事件机制,页面跳转等常用操作

    点击时间2种 第一种,通过初始化页面 写入点击事件 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedI ...

  2. 点击<a>标签后禁止页面跳至顶部

    一.点击<a>标签后禁止页面跳至顶部 1. 使用 href="javascript:void(0);",例如: <a href="javascript: ...

  3. Android ListView item 点击事件失效问题的解决

    关于ListView点击无效,item无法相应点击事件的问题,网上有很多, 大致可分为俩种情况, 一种是 item中存在 ImageButton 等可以点击的组件,这会抢先获得ListView的焦点. ...

  4. Android笔记——Button点击事件几种写法

    Button点击事件:大概可以分为以下几种: 匿名内部类 定义内部类,实现OnClickListener接口 定义的构造方法 用Activity实现OnClickListener接口 指定Button ...

  5. Android四种点击事件和五中存储方式

    Android点击事件的四种实现方式 1.内部类实现onClickListenter接口 bt_login.setOnClickListener(new MyListener()); class My ...

  6. Android多次点击事件的监听和处理

    package com.example.administrator.mystudent.MoreClick; import android.os.SystemClock; import android ...

  7. Android监听点击事件实现的三种方法

    监听点击事件实现的三种方法:1.匿名内部类2.外部类3.直接实现接口 1.匿名内部类: package com.jereh.calculator; import android.content.Con ...

  8. Android学习-----Button点击事件几种写法

    Button点击事件:大概可以分为以下几种: 匿名内部类 定义内部类,实现OnClickListener接口 定义的构造方法 用Activity实现OnClickListener接口 指定Button ...

  9. Android开发之点击事件(Button)

    Button点击事件 创建项目: 1.Fiel-------->New ------->Android Application Project 2.将Form Widght 文件中的But ...

随机推荐

  1. 微信二次认证 C#

    using Senparc.Weixin.Entities; using Senparc.Weixin.HttpUtility; using Senparc.Weixin.QY.AdvancedAPI ...

  2. 07 Django组件-中间件

    中间件 方式一:函数式:中间件[middleware],也叫钩子方法[钩子函数],hook Django中的中间件是一个轻量级.底层的插件系统,可以介入Django的请求和响应处理过程,修改Djang ...

  3. 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

    这是在复制代码的时候,没有修改路径,但是IDEA没有报错,还会爆出 WARN ework.web.servlet.PageNotFound - No mapping found for HTTP re ...

  4. node——通过express模拟Apache实现静态资源托管

    1.express中处理静态资源的函数 创建一个app.js作为入口文件,创建一个public文件夹作为静态资源文件夹 var app=express();var fn=express.static( ...

  5. elasticsearch聚合函数

    计算每个tag下的商品数量 GET /ecommerce/product/_search { "aggs": {  //聚合 "group_by_tags": ...

  6. JavaScript进阶【二】JavaScript 严格模式(use strict)的使用

    /*** *使用严格模式的原因: * ①:消除Javascript语法的一些不合理.不严谨之处,减少一些怪异行为; ②:消除代码运行的一些不安全之处,保证代码运行的安全: ③:提高编译器效率,增加运行 ...

  7. Selenium+Python+jenkins搭建web自动化测测试框架

    python-3.6.2 chrome 59.0.3071.115 chromedriver 2.9 安装python https://www.python.org/downloads/  (Wind ...

  8. HDU1527 - 取石子游戏【威佐夫博弈】

    有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后把石子全部取完者为胜者. ...

  9. java的基本数据类型及运算符等

    基本数据类型 一.整数(整形) 值域 1. byte [-128,127] 2.short [-32768,32767] 3.int [-2147483648,2147483647] 4.long [ ...

  10. uni-app 路由navigate

    uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台. 公司最近在写APP应用到了uni-app  我在写的时 ...