学习了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. eclipse使用sublime配色(转)

    转自 Eclipse设置类似Sublime Text 编辑区皮肤,风格,颜色 1.首先打开eclipse 2.help -> Install New SoftWare  3.点击 Add 在Na ...

  2. HotSpot JVM常用参数设置

    转自:https://www.zybuluo.com/jewes/note/57352 选项的分类 Hotspot JVM提供以下三大类选项: 1. 标准选项:这类选项的功能是很稳定的,在后续版本中也 ...

  3. React的井字过三关(2)

    这篇笔记是官方教程的延续笔记,所有代码基于第一篇笔记的结尾代码.旨在解决教程后面提出的五个问题. 一 . 用(X,Y)来取代原有的数字坐标 原来的数字坐标是这样的: 现在的要求是把原来的代码坐标改为二 ...

  4. Nginx设置线程数为整机内核数的俩倍!

    Nginx设置线程数为整机内核数的俩倍!

  5. mysql 主主复制搭建用的命令

    # mysql 容器的启动docker run -d -p 3306:3306 -v /database_files/products/data:/var/lib/mysql -v /database ...

  6. HDOJ 1358

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. UI第十九节——UICollectionView

    UICollectionView其实就是UITableView的升级版,在布局方面比UITableView更出色.下面,先看代码吧 #import "RootViewController.h ...

  8. bzoj1492 斜率优化|cdq分治

    #include <stdio.h> #include <bitset> #include <string.h> #include <stack> #i ...

  9. MFC去掉标题栏

    在初始化的时候加入以下函数 //去掉标题栏 ModifyStyle(WS_CAPTION, NULL, SWP_DRAWFRAME );

  10. javascript星级评分(多个)

    JS打多个类型星级评分: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...