论Activity的互相转换

这次任务是实现

1.在主屏幕输入自己的姓名,单击评估按钮

2.进入第二个界面,并将主屏幕输入的姓名传递给第二个界面

3.在第二个界面进行问题回答;

4.第二个界面的回答结果返回第一个界面并显示


布局很简单 不说了 直接上代码

两个界面两个布局

 <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yy_pg"
android:textSize="30sp"
android:textColor="?android:attr/colorMultiSelectHighlight" />
<ImageView
android:layout_width="150sp"
android:layout_height="150sp"
android:layout_gravity="center"
android:src="@drawable/btm1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 请输入姓名:"
android:textSize="25sp"
android:textColor="@android:color/background_dark" />
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="50sp"
android:ems="12" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_ing"
style="@style/Button"
android:text="@string/yy_ing"
android:onClick="onClick"
android:textSize="25sp"/>
<Button
android:id="@+id/btn_end"
style="@style/Button"
android:text="@string/yy_end"
android:onClick="onClick"
android:textSize="25sp"/>
</LinearLayout>
<ImageView
android:layout_width="400sp"
android:layout_height="50sp"
android:layout_gravity="center"
android:src="@drawable/btm2"/>
<TextView
android:id="@+id/yy_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="评估结果"
android:layout_gravity="center"
android:textSize="25sp"
android:textColor="@android:color/background_dark" />

<TextView
android:id="@+id/yy_yf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="30sp"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="166dp"/> <TextView
android:id="@+id/yy_st"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="有"
android:textSize="25sp"
android:id="@+id/btn_you"
android:onClick="onClick"/> <Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="25sp"
android:text="没有"
android:id="@+id/btn_wu"
android:onClick="onClick"/>
</LinearLayout>


然后是Java部分的代码 时间原因就不废话了 再磨叽可能会交不了作业的


public class MainActivity extends AppCompatActivity { private EditText etname; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etname= (EditText) findViewById(R.id.et_name);
try{
Intent intent=getIntent();
String pgjg=intent.getStringExtra("result");
TextView yyresult=(TextView)findViewById(R.id.yy_result);
yyresult.setText(pgjg);
}catch (Exception e){} }
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_ing:
ing();
case R.id.btn_end:
finish();
break;
}
} private void ing() {
Intent intent = new Intent();
intent.setClass(MainActivity.this,MainActivity2.class);
String text = etname.getText().toString();
intent.putExtra("name",text+"同学:对学习安卓有没有信心?");
startActivity(intent);
}

以上第一个布局的Java代码 进行界面的跳转 传递数据

public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2); Intent intent=getIntent();
String pgjg=intent.getStringExtra("name");
TextView question=(TextView)findViewById(R.id.yy_st);
question.setText(pgjg); }
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_you:
you();
break;
case R.id.btn_wu:
wu();
break;
}
} private void you() {
Intent intent = new Intent();
intent.setClass(MainActivity2.this,MainActivity.class);
intent.putExtra("result","评估结果:对学习安卓有信心");
startActivity(intent);
finish();
} private void wu() {
Intent intent = new Intent();
intent.setClass(MainActivity2.this,MainActivity.class);
intent.putExtra("result","评估结果:对学习安卓没有信心");
startActivity(intent);
finish();
}

以上是第二个Java的代码 接收数据 进行评估之后返回第一个界面并且显示评估结果

任务到此结束。

论Activity的转换的更多相关文章

  1. [转]Android之Context和Activity互相转换

    1.context转换为activity Activity activity = (Activity) context; 2.从activity得到context 在activity的方法中用cont ...

  2. Android之Context和Activity互相转换

    1.context转换为activity Activity activity = (Activity) context; 2.从activity得到context 在activity的方法中用cont ...

  3. 使用adb shell dumpsys检测Android的Activity任务栈

    谈起Android程序开发,就需要了解其四个主要的部件:Activity.Service.ContentProvider. BroadcastReceiver.而其中Activity是唯一直接控制程序 ...

  4. Android群英传笔记——第八章:Activity与Activity调用栈分析

    Android群英传笔记--第八章:Activity与Activity调用栈分析 开篇,我们陈述一下Activity,Activity是整个应用用户交互的核心组件,了解Activity的工作模式,生命 ...

  5. Android四大组件之——Activity(一)定义、状态和后退栈(图文详解)

    什么是Activity 关键字:应用组件.四大组件.用户界面,交互. An Activity is an application component that provides a screen wi ...

  6. 1.2 Activity

    Activity是个应用组件,它给用户提供了为了完成某些工作而可以进行交互操作的界面,例如,电话详情,打电 话,发邮件,或是浏览地图.每一个Activity都有一个窗口来绘制自已的用户界面.通常来说, ...

  7. Android学习笔记4——Activity详解

    在 Android 开发过程中,与程序员打交道最多的应该就是作为四大组件之一的 Activity 了.接下来我们就一起来揭开 Activity 的神秘面纱吧~ 一.概述 什么是 Activity(活动 ...

  8. Android组件内核之Activity调用栈分析(一)

    阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 导语 我们陈述一下Activity,Activity是整个应用用户交互的 ...

  9. Android官方文档翻译 十八 4.2Pausing and Resuming an Activity

    Pausing and Resuming an Activity 暂停和恢复一个activity This lesson teaches you to 这节课教给你 Pause Your Activi ...

随机推荐

  1. [Linux]系统管理: 进程管理(ps/top/pstree/kill/pkill), 工作管理, 系统资源查看, 系统定时任务

    进程管理:查看与终止 进程查看 1. 进程是正在执行的程序或命令. 2. 进程管理的作用: 判断服务器健康状态, 查看系统中所有进程 杀死进程 3. 查看系统中所有进程 ps aux    # 查看系 ...

  2. [SF] Symfony 在 console 中结合 Workerman

    在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式. workerman 对命令的解析是 ...

  3. MySQL 权限相关

    # ============================= mysql 权限相关 =====================================================gran ...

  4. JSP/Servlet基础

    动态网页的技术 html+css javascript(弱语言) jquery(改造) jsp(java的html) servlet(核心) S2SH:structs2 (springmvc) spr ...

  5. 想拥有自己的Python程序包,你只需15步

    来源商业新知网,原标题:15步,你就能拥有自己的Python程序包 全文共 3192 字,预计学习时长 6 分钟 每个软件开发员和数据科学家都难免要做程序包.本文推荐一篇 Python开源程序包的制作 ...

  6. [ts] Property 'aaa' does not exist on type 'Window' 解决办法

    第一种: (window as any).aaa 第二种: declare global { interface Window { aaa: any; } } window.aaa = window. ...

  7. MVC过滤器使用方法

    先介绍下什么是过滤器:ASP.NET MVC中的灭一个请求,都会分配给相应的控制器和对应的行为方法去处理,而在这些处理的前前后后如果想再加一些额外的逻辑处理,这时就用到了过滤器. MVC支持的过滤器有 ...

  8. javaMail实现收发邮件(五)

    控制台打印出的内容,我们无法阅读,其实,让我们自己来解析一封复杂的邮件是很不容易的,邮件里面格式.规范复杂得很.不过,我们所用的浏览器内置了解析各种数据类型的数据处理模块,我们只需要在把数据流传输给浏 ...

  9. 数字证书原理(ssl,https)

    文中首先解释了加密解密的一些基础知识和概念,然后通过一个加密通信过程的例子说明了加密算法的作用,以及数字证书的出现所起的作用.接着对数字证书做一个详细的解释,并讨论一下windows中数字证书的管理, ...

  10. [Mysql]一些知识点

    Mysql引擎类型 InnoDB: 行级锁->写性能略优:支持事务 MYISAM: 表级锁->读性能优:不支持事务 表示时间的类型 datetime 可表示时间范围大 1000-9999. ...