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

首先在.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. (转载) IaaS, PaaS, Saas

    如果你是一个网站站长,想要建立一个网站.不采用云服务,你所需要的投入大概是:买服务器,安装服务器软件,编写网站程序. 现在你追随潮流,采用流行的云计算,如果你采用 IaaS 服务,那么意味着你就不用自 ...

  2. 编译OpenCV遇到Qmake问题

    1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...

  3. jmeter搭建

    jdk 1.8的地址  链接:https://pan.baidu.com/s/1eEyYbzo1Tfbvbmf_vN2yUA 密码:6dxi 1.安装JDK 选择安装目录 安装过程中会出现两次 安装提 ...

  4. 探索JS引擎工作原理 (转)

    这篇文章从相对底层的角度介绍了js引擎的工作 引入了 静态作用域 执行环境上下文(context) 等概念 , http://www.cnblogs.com/onepixel/p/5090799.ht ...

  5. Codeforces Round #471 (Div. 2)A. Feed the cat

    After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another ...

  6. 喵哈哈村的魔法考试 Round #3 (Div.2)

    菜的抠脚 A 题解:判断能否构成一个三角形. #include "iostream" #include "algorithm" #include "c ...

  7. uni-app 之验证码

    手机APP---验证码 最近公司在开发手机APP,app避不可免的就是登录了,emmmm 登录验证码那必须的是有的,我们公司发给我们的图片是酱紫的~~ 这个要求大家应该都能看懂,做这个手机号啊,验证码 ...

  8. 企业级工作流解决方案(十三)--集成Abp和ng-alain--数据库读写分离

    说到程序里面数据库管理,无非就是两件事情,一是数据库操作,对于数据库的操作,各种程序语言都有封装,也就是所谓的ORM框架,.net 方向一般用得比较多和就是.net framework和dapper, ...

  9. 使用c++Beep实现春节十二响蜂鸣程序

    直接编译运行即可 #include<bits/stdc++.h> #include<windows.h> using namespace std; char a[31][71] ...

  10. 【Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D】The Wu

    [链接] 我是链接,点我呀:) [题意] 给你n个字符串放在multiset中. 这些字符串都是长度为m的01串. 然后给你q个询问 s,k 问你set中存在多少个字符串t 使得∑(t[i]==s[i ...