学习了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的更多相关文章

  1. Android笔记---Intent实现Activity跳转

    学了之前的Android控件以及布局,我们就能够做一些UI的设计了,这里我结合之前的知识.以一个小的登录项目来解说下Activity之间跳转. 先看下效果图: 1.登录界面: 2.点击登录按钮跳转到另 ...

  2. Android 用Intent和Bundle传递参数

    传递方: //点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText() private void setListeners()    {    ...

  3. [转]android笔记--Intent和IntentFilter详解

    Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启 ...

  4. android笔记--Intent和IntentFilter详解

    本文转载自:https://www.cnblogs.com/liushengjie/archive/2012/08/30/2663066.html 本文转载自:https://www.cnblogs. ...

  5. Android(java)学习笔记146:Bundle和Intent类使用和交互

            Bundle只是一个信息的载体 将内部的内容以键值对组织 ,Intent负责Activity之间的交互自己是带有一个Bundle的.Intent.putExtras(Bundle bu ...

  6. Android(java)学习笔记89:Bundle和Intent类使用和交互

    1. Bundle 和 Intent:    Bundle只是一个信息的载体 将内部的内容以键值对组织 ,Intent负责Activity之间的交互自己是带有一个Bundle的.Intent.putE ...

  7. Android学习笔记-Intent(一)

    Intent对象在Android官方API这样描述:It is a passive data structure holding an abstract description of an opera ...

  8. Android笔记一.深入理解Intent和IntentFilters(一)

    深入理解Intent和IntentFiler(一) 转载请表明出处:http://blog.csdn.net/u012637501(嵌入式_小J的天空)     为了比較深刻的理解并灵活使用Inten ...

  9. Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)

    前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...

随机推荐

  1. 谷歌浏览器,火狐浏览器,ie浏览器解析顺序

    谷歌(版本 55.0.2883.87 m),火狐(48.0.2),ie(11.576.14393.0)对三个浏览器简单的进行了一下试验发现,谷歌浏览器是等到html全部解析完毕之后才开始渲染,而另外两 ...

  2. React.js入门笔记(再续):评论框的实现

    本案例来自React.js中文官网对应内容. 一. 运行环境 <link rel="stylesheet" type="text/css" href=&q ...

  3. linux 系统、命令、软件

    软件名称:Putty 使用方法:http://jingyan.baidu.com/article/e73e26c0eb063324adb6a737.html 需要资料: 服务IP:228.5624.5 ...

  4. Node.js之路【第二篇】Nodejs中的pip(NPM)&REPL

    什么是NPM 在学Python的时候我们肯定会使用第三方模块或者编写模块供别人使用,我们有一个非常好用的pip来帮我们管理我们的模块包!那么Nodejs重的模块包呢? 对没错就是NPM,他是随同Nod ...

  5. iOS8新特性(1)-UIPopoverPresentationController使用

    从iOS 8开始,苹果提出新的 UIPopoverPresentationController代替UIPopoverController: 新的UIPopoverPresentationControl ...

  6. 关于JSF中immediate属性的总结(二)

    The immediate attribute in JSF is commonly misunderstood. If you don't believe me, check out Stack O ...

  7. style,currentStyle,getComputedStyle的区别和用法

    先说说层叠样式表的三种形式(三种的叫法不一,按照各自的习惯): 一.内联样式:在HTML标签用style属性设置.如: 1 <p >这是内联样式</p> 二.嵌入样式:通过&l ...

  8. 03 Yarn 原理介绍

    Yarn 原理介绍 大纲: Hadoop 架构介绍 YARN 产生的背景 YARN 基础架构及原理   Hadoop的1.X架构的介绍   在1.x中的NameNodes只可能有一个,虽然可以通过Se ...

  9. 【Android】Ignoring InnerClasses attribute for an anonymous inner class

    这个问题是因为Android只能有6w个方法,解决方法,在defaultConfig中加入一句:multiDexEnabled true

  10. shell脚本重新挂载出问题的卷

    #!/bin/bash#卷的全路径示例#pathexample =mount -t cetusfs 127.0.0.1:/cinderv/var/lib/cinder/volumes/0f6a20f4 ...