论Activity的转换
论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的转换的更多相关文章
- [转]Android之Context和Activity互相转换
1.context转换为activity Activity activity = (Activity) context; 2.从activity得到context 在activity的方法中用cont ...
- Android之Context和Activity互相转换
1.context转换为activity Activity activity = (Activity) context; 2.从activity得到context 在activity的方法中用cont ...
- 使用adb shell dumpsys检测Android的Activity任务栈
谈起Android程序开发,就需要了解其四个主要的部件:Activity.Service.ContentProvider. BroadcastReceiver.而其中Activity是唯一直接控制程序 ...
- Android群英传笔记——第八章:Activity与Activity调用栈分析
Android群英传笔记--第八章:Activity与Activity调用栈分析 开篇,我们陈述一下Activity,Activity是整个应用用户交互的核心组件,了解Activity的工作模式,生命 ...
- Android四大组件之——Activity(一)定义、状态和后退栈(图文详解)
什么是Activity 关键字:应用组件.四大组件.用户界面,交互. An Activity is an application component that provides a screen wi ...
- 1.2 Activity
Activity是个应用组件,它给用户提供了为了完成某些工作而可以进行交互操作的界面,例如,电话详情,打电 话,发邮件,或是浏览地图.每一个Activity都有一个窗口来绘制自已的用户界面.通常来说, ...
- Android学习笔记4——Activity详解
在 Android 开发过程中,与程序员打交道最多的应该就是作为四大组件之一的 Activity 了.接下来我们就一起来揭开 Activity 的神秘面纱吧~ 一.概述 什么是 Activity(活动 ...
- Android组件内核之Activity调用栈分析(一)
阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 导语 我们陈述一下Activity,Activity是整个应用用户交互的 ...
- Android官方文档翻译 十八 4.2Pausing and Resuming an Activity
Pausing and Resuming an Activity 暂停和恢复一个activity This lesson teaches you to 这节课教给你 Pause Your Activi ...
随机推荐
- [Linux]Ubuntu与终端破墙
参考:https://www.jianshu.com/p/941bf811f9c2 亲测在ubuntu-14.04.4-desktop-amd64.iso上安装成功 福利:https://github ...
- EXCEL文本字符串转日期
=IF(ISERROR(DATEVALUE(A2)), A2, DATEVALUE(A2)) 注意ISERROR函数的使用,如果DATEVALUE解析字符串失败,比如单元格数值本来就是日期,会发挥#V ...
- hbase版本升级的api对比
前言 今天来介绍一下,hbase的2.1.0版本升级之后和1.2.6版本的api方法的一些不同之处. hbase的工具类 在介绍hbase的相关的java api之前,这里先介绍一下hbase的工具类 ...
- javascript中如何判断变量类型
typeof 只能判断基本类型,如number.string.boolean.当遇上引用类型变量就没那么好用了,结果都是object.使用Object.prototype.toString.call( ...
- ARTS打卡计划第一周-Review
本周分享的文章来自于medium的 Testing Best Practices for Java + Spring Apps 这个文章主要讲的是java测试的一些最佳实践 1.避免函数返回void, ...
- React—Native开发之 Could not connect to development server(Android)解决方法
作为初学者昨天还好好能跑的项目今天就会遇到突然爆红出错是经常的事,让我们来看下是什么错吧 先来翻译: 连接不到开发的服务器. 请按照以下的步骤来修复此问题: 确保包服务器在运行确保你的设备或者模拟器连 ...
- [LINQ] group by 与连接查询
//副表 树种-品名-折材率 汇总 var listNeed = (from t in dtNeed.AsEnumerable() group t by new { t1 = t.Field<s ...
- pyautogui 文档(五):截图及定位功能
截图函数 PyAutoGUI可以截取屏幕截图,将其保存到文件中,并在屏幕中查找图像.如果您有一个小图像,例如需要单击并希望在屏幕上找到它的按钮,这将非常有用.这些功能由PyScreeze模块提供,该模 ...
- XML Linq 学习笔记
XML如下: <?xml version="1.0" encoding="utf-8"?> <Dishes> <Dish> ...
- Sql 根据当前时间,获取星期一具体日期
--根据当前时间,计算每周一日期,周日为每周第一天 declare @getDate datetime --set @getDate='2018-12-30' set @getDate='2019-0 ...