学习了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. ios开发之Info.plist文件相关配置

    前言:在iOS开发中有些情况下需要对Info.plist文件进行配置,以下介绍几种相关配置.以后遇到需要配置的再更新... 开发环境:swift3.0.1,Xcode8.1 一,项目中需要使用第三方字 ...

  2. Spring MVC学习笔记——SiteMesh的使用(转)

    转自 SiteMesh的使用 SiteMesh的介绍就不多说了,主要是用来统一页面风格,减少重复编码的. 它定义了一个过滤器,然后把页面都加上统一的头部和底部. 需要先在WEB-INF/lib下引入s ...

  3. docker run mysql

    sudo docker run --name=mysqlserver -e MYSQL_ROOT_PASS=123456 -v /srv/mysql/data:/data/mysql -d -p : ...

  4. Android之ListView性能优化——一行代码绑定数据——万能适配器

    如下图,加入现在有一个这样的需求图,你会怎么做?作为一个初学者,之前我都是直接用SimpleAdapter结合一个Item的布局来实现的,感觉这样实现起来很方便(基本上一行代码就可以实现),而且也没有 ...

  5. window server 2008配置FTP服务器550 Access is denied. 问题解决办法

    如果你是按照网上的通用方法,在搭建FTP服务器的时候临时建了一个用户的话,那么这个用户是普通用户,你即便勾选了“读”“写”权限,那么再打开防火墙的情况下,你还是不能上传文件,只能下载.只需要登录到服务 ...

  6. nyoj 473 A^B Problem

    A^B Problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Give you two numbers a and b,how to know the a^ ...

  7. [Machine Learning & Algorithm]CAML机器学习系列2:深入浅出ML之Entropy-Based家族

    声明:本博客整理自博友@zhouyong计算广告与机器学习-技术共享平台,尊重原创,欢迎感兴趣的博友查看原文. 写在前面 记得在<Pattern Recognition And Machine ...

  8. 记一次Suse下的Django环境配置——第一弹

    一.安装Python 由于原有Suse自带的Python版本只有2.4,因此首先需要安装Python的高版本,在这里我选择使用Python2.7.9.PS:之前选择使用2.7.11版本,由于没有zli ...

  9. C++网络套接字编程TCP和UDP实例

    原文地址:C++网络套接字编程TCP和UDP实例作者:xiaojiangjiang 1.       创建一个简单的SOCKET编程流程如下 面向有连接的套接字编程 服务器: 1)  创建套接字(so ...

  10. applicationContext.xml的基本配置文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...