Android 笔记 Intent and Bundle day7
学习了Intent与Bundle的使用,进行应用中的交互
package com.example.intent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
public class MainActivity extends Activity {
RadioGroup RG_OS;
RadioButton r1,r2,r3;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RG_OS=(RadioGroup) this.findViewById(R.id.GR_OS);
r1=(RadioButton) this.findViewById(R.id.radio0);
r2=(RadioButton) this.findViewById(R.id.radio1);
r3=(RadioButton) this.findViewById(R.id.radio2);
b1=(Button)this.findViewById(R.id.button1);
b1.setOnClickListener(new ButtonClickListener());
}
class ButtonClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myintent=new Intent();
myintent.setClass(MainActivity.this, MainActivity2.class);
Bundle mybundle=new Bundle();
if(r1.isChecked()) mybundle.putString("selected", (String)r1.getText());
else if(r2.isChecked()) mybundle.putString("selected", (String)r2.getText());
else if(r3.isChecked()) mybundle.putString("selected", (String)r3.getText());
myintent.putExtras(mybundle);
MainActivity.this.startActivity(myintent);
MainActivity.this.finish();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
界面1
package com.example.intent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
public class MainActivity2 extends Activity {
Button b_back;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
b_back=(Button) this.findViewById(R.id.button_back);
TextView textview=(TextView) this.findViewById(R.id.textView1);
b_back.setOnClickListener(new bc1());
Intent myintent=this.getIntent();
Bundle mybundle=myintent.getExtras();
String selected=mybundle.getString("selected");
if(selected=="null"){
textview.setText("No selected any OS");
}
else{
textview.setText(selected+"is selected");
}
}
class bc1 implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myintent=new Intent();
myintent.setClass(MainActivity2.this, MainActivity.class);
MainActivity2.this.startActivity(myintent);
MainActivity2.this.finish();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
界面2
Android 笔记 Intent and Bundle day7的更多相关文章
- Android笔记---Intent实现Activity跳转
学了之前的Android控件以及布局,我们就能够做一些UI的设计了,这里我结合之前的知识.以一个小的登录项目来解说下Activity之间跳转. 先看下效果图: 1.登录界面: 2.点击登录按钮跳转到另 ...
- Android 用Intent和Bundle传递参数
传递方: //点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText() private void setListeners() { ...
- [转]android笔记--Intent和IntentFilter详解
Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启 ...
- android笔记--Intent和IntentFilter详解
本文转载自:https://www.cnblogs.com/liushengjie/archive/2012/08/30/2663066.html 本文转载自:https://www.cnblogs. ...
- Android(java)学习笔记146:Bundle和Intent类使用和交互
Bundle只是一个信息的载体 将内部的内容以键值对组织 ,Intent负责Activity之间的交互自己是带有一个Bundle的.Intent.putExtras(Bundle bu ...
- Android(java)学习笔记89:Bundle和Intent类使用和交互
1. Bundle 和 Intent: Bundle只是一个信息的载体 将内部的内容以键值对组织 ,Intent负责Activity之间的交互自己是带有一个Bundle的.Intent.putE ...
- Android学习笔记-Intent(一)
Intent对象在Android官方API这样描述:It is a passive data structure holding an abstract description of an opera ...
- Android笔记一.深入理解Intent和IntentFilters(一)
深入理解Intent和IntentFiler(一) 转载请表明出处:http://blog.csdn.net/u012637501(嵌入式_小J的天空) 为了比較深刻的理解并灵活使用Inten ...
- Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)
前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...
随机推荐
- redis技巧--自动完成功能实现
自动完成功能一般都伴随搜索框出现,就是用户在输入时帮助其自动补全. 比如对成语进行补全,现有如下成语:一心一意,一心二用,一帆风顺. 两种实现方式: 实现方式一: 为每个成语的每个前缀都使用一个集合类 ...
- jquery 返回顶部 兼容web移动
返回顶部图片 http://hovertree.com/texiao/mobile/6/tophovertree.gif 具体实现代码 <span id="tophovertree&q ...
- Spring Boot整合Dubbo框架demo
Dubbo框架原理见之前的博文:http://www.cnblogs.com/umgsai/p/5836925.html 首先启动zookeeper Server端 Pom配置如下 <?xml ...
- 在QtCreator中使用doxygen
接触Doxygen后,认识到其强大之处,一口气将之前的烂代码重构了一遍,所有的文件头,函数注释等等都是手动添加注释.在keil中可以看到其对JavaDoc风格的注释有高亮,非常好看.但是keil这个I ...
- 兼容好的JS图片上传预览代码
转 : http://www.codefans.net/articles/1395.shtml 兼容好的JS图片上传预览代码 (谷歌,IE11) <html xmlns="http:/ ...
- 第4月第2天 nsinvocation崩溃 mvc videotrack
1. __unsafe_unretained id result = nil; [invocation getReturnValue:&result]; return result; http ...
- ubuntu14.04下搭建python+mysql环境
简略记录ubuntu14.04下搭建python操作的mysql服务器的过程和其中遇到的问题及解决方法. 第一部分: 安装mysql 安装步骤:1. sudo apt-get install mysq ...
- win10 Vmware12装mac os X10.11虚拟机教程
1.下载安装VMware 12,具体教程在网上都能看见. 2.下载mac os的镜像,最好下载cdr格式的. 3.在导入虚拟机的时候,到选择客户机操作系统的时候,没有网上出现的Mac os,如下图所示 ...
- 如何灵活运用Linux 进程资源监控和进程限制
导读 每个 Linux 系统管理员都应该知道如何验证硬件.资源和主要进程的完整性和可用性.另外,基于每个用户设置资源限制也是其中一项必备技能. 在这篇文章中,我们会介绍一些能够确保系统硬件和软件正常工 ...
- Linux kernel make 常用选项介绍
Linux kernel 编译方法大全记录 一.这是一个我自己写的自动make脚本: #!/bin/sh export ARCH=arm export CROSS_COMPILE=arm-linux- ...