码迷,mamicode.com
首页 > 移动开发 > 详细

从零开始学android<Intent初步.四十.>

时间:2014-09-10 00:23:39      阅读:464      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   os   io   使用   java   ar   

Intent意图是android中非常重要的部分,他在Activity,service中有较为广泛的应用。

 

1
public void startActivity(Intent intent)
普通
启动一个Activity,并通过Intent传送数据
2
public void startActivityForResult(Intent intent, int requestCode)
普通
启动并接收另一个Activity程序回传数据,当requestCode大于0才可以触发onActivityResult()
3
public Intent getIntent()
普通
返回启动当前Activity程序的Intent
4
protected void onActivityResult(int requestCode, int resultCode, Intent data)
普通
当需要接收Intent回传数据的时候覆写此方法对回传操作进行处理
5
public void finish()
普通
调用此方法会返回之前的Activity程序,并自动调用onActivityResult()方法
6
public final Cursor managedQuery (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
普通
处理返回的Cursor结果集


接下里用例子逐步讲解


最简单的Intent

主界面xml

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:text="@string/hello_world" />  
  15.   
  16.     <Button  
  17.         android:id="@+id/button1"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_alignParentBottom="true"  
  21.         android:layout_centerHorizontal="true"  
  22.         android:layout_marginBottom="141dp"  
  23.         android:text="转跳" />  
  24.   
  25. </RelativeLayout>  

转跳界面Xml
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:text="我是第二屏界面" />  
  15.   
  16. </RelativeLayout>  


  1. package com.example.intent1;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.content.Intent;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.widget.Button;  
  9.   
  10. public class MainActivity extends Activity {  
  11.     private Button button;  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_main);  
  17.         button = (Button) this.findViewById(R.id.button1);  
  18.         button.setOnClickListener(new View.OnClickListener() {  
  19.   
  20.             @Override  
  21.             public void onClick(View v) {  
  22.                 // TODO Auto-generated method stub  
  23.                 Intent intent = new Intent(MainActivity.this, Other.class);//创建Intent 对象  
  24.                 startActivity(intent);//开启intent  
  25.                 MainActivity.this.finish();//使当前Activity结束  
  26.             }  
  27.         });  
  28.   
  29.     }  
  30.   
  31. }  


Otner.java
  1. package com.example.intent1;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.text.style.SuperscriptSpan;  
  6.   
  7. public class Other extends Activity {  
  8. @Override  
  9. protected void onCreate(Bundle savedInstanceState) {  
  10.     // TODO Auto-generated method stub  
  11.     super.onCreate(savedInstanceState);  
  12.     setContentView(R.layout.other);  
  13. }  
  14. }  


bubuko.com,布布扣


bubuko.com,布布扣


接下来看一看可以传递数据的Intent



  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <Button  
  12.         android:id="@+id/button1"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:layout_alignParentBottom="true"  
  16.         android:layout_centerHorizontal="true"  
  17.         android:text="传递" />  
  18.   
  19.     <EditText  
  20.         android:id="@+id/edit"  
  21.         android:layout_width="wrap_content"  
  22.         android:layout_height="wrap_content"  
  23.         android:layout_alignParentTop="true"  
  24.         android:layout_centerHorizontal="true"  
  25.         android:ems="10"  
  26.         android:text=" />  
  27.   
  28. </RelativeLayout>  
  29. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  30.     xmlns:tools="http://schemas.android.com/tools"  
  31.     android:layout_width="match_parent"  
  32.     android:layout_height="match_parent"  
  33.     android:paddingBottom="@dimen/activity_vertical_margin"  
  34.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  35.     android:paddingRight="@dimen/activity_horizontal_margin"  
  36.     android:paddingTop="@dimen/activity_vertical_margin"  
  37.     tools:context=".MainActivity" >  
  38.   
  39.     <Button  
  40.         android:id="@+id/button1"  
  41.         android:layout_width="wrap_content"  
  42.         android:layout_height="wrap_content"  
  43.         android:layout_alignParentBottom="true"  
  44.         android:layout_centerHorizontal="true"  
  45.         android:text="传递" />  
  46.   
  47.     <EditText  
  48.         android:id="@+id/edit"  
  49.         android:layout_width="wrap_content"  
  50.         android:layout_height="wrap_content"  
  51.         android:layout_alignParentTop="true"  
  52.         android:layout_centerHorizontal="true"  
  53.         android:ems="10"  
  54.         android:text="" />  
  55.   
  56. </RelativeLayout>  


Other.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/textView1"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="TextView" />  
  12.   
  13.     <Button  
  14.         android:id="@+id/button2"  
  15.         android:gravity="center_horizontal"  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:text="获取数据" />  
  19.   
  20. </LinearLayout>  



java文件


  1. package com.example.intent2;  
  2.   
  3. import android.os.Bundle;  
  4. import android.R.integer;  
  5. import android.app.Activity;  
  6. import android.content.Intent;  
  7. import android.view.Menu;  
  8. import android.view.View;  
  9. import android.widget.Button;  
  10. import android.widget.EditText;  
  11.   
  12. public class MainActivity extends Activity {  
  13. private Button button;  
  14. private EditText info;  
  15.     @Override  
  16.     protected void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.activity_main);  
  19.   button=(Button)this.findViewById(R.id.button1);  
  20.   info=(EditText)this.findViewById(R.id.edit);  
  21.   button.setOnClickListener(new View.OnClickListener() {  
  22.       
  23.     @Override  
  24.     public void onClick(View v) {  
  25.         // TODO Auto-generated method stub  
  26.     Intent intent=new Intent(MainActivity.this,Other.class);//设置意图  
  27.                 intent.putExtra("info", info.getText().toString());//为意图增加附加信息  
  28.     startActivity(intent);//开始意图  
  29.     MainActivity.this.finish();//终止当前Ativity  
  30.     }  
  31. });  
  32.           
  33.     }  
  34.       
  35. }  


Other.java

  1. package com.example.intent2;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. import android.widget.TextView;  
  9. public class Other extends Activity {  
  10.     Intent intent;  
  11.     private Button button;  
  12.     private TextView text;  
  13. @Override  
  14.   
  15. protected void onCreate(Bundle savedInstanceState) {  
  16.     // TODO Auto-generated method stub  
  17.     super.onCreate(savedInstanceState);  
  18.     super.setContentView(R.layout.other);  
  19.     button=(Button)this.findViewById(R.id.button2);  
  20.     text=(TextView)this.findViewById(R.id.textView1);  
  21.     intent=super.getIntent();//获取意图对象  
  22.     button.setOnClickListener(new View.OnClickListener() {  
  23.           
  24.         @Override  
  25.         public void onClick(View v) {  
  26.             // TODO Auto-generated method stub  
  27.           
  28.             String info=intent.getStringExtra("info");//获取传递的数据  
  29.             text.setText(info);//显示数据  
  30.         }  
  31.     });  
  32.       
  33.       
  34. }  
  35. }  


bubuko.com,布布扣



bubuko.com,布布扣


使用Intent传递并返回数据

借助Intent实现成人身高体重测试程序
采用BMI 法 
 
体重指数 =  体重(公斤) 除 身高(米)的平方    kg/m2      
正常体重 : 体重指数 = 18 - 25 
超重           : 体重指数 = 25 - 30 
轻度肥胖 : 体重指数 > 30 
中度肥胖 : 体重指数 > 35 
重度肥胖 :  体重指数 > 40 

xml

  1. package com.example.inten3;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.content.Intent;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.widget.Button;  
  9. import android.widget.EditText;  
  10. import android.widget.TextView;  
  11.   
  12. public class MainActivity extends Activity {  
  13. private Button resetInfo,getInfo;  
  14. private EditText height,weight;  
  15. private TextView detail;  
  16.     @Override  
  17.     protected void onCreate(Bundle savedInstanceState) {  
  18.         super.onCreate(savedInstanceState);  
  19.    super.setContentView(R.layout.activity_main);  
  20.    resetInfo=(Button)this.findViewById(R.id.button1);//重置信息按钮  
  21.    getInfo=(Button)this.findViewById(R.id.button2);//获取信息按钮  
  22.    height=(EditText)this.findViewById(R.id.editText1);//身高输入框  
  23.    weight=(EditText)this.findViewById(R.id.editText2);//体重输入框  
  24.    detail=(TextView)this.findViewById(R.id.textView3);//信息显示  
  25. //   重置按钮的监听  
  26.    resetInfo.setOnClickListener(new View.OnClickListener() {  
  27.       
  28.     @Override  
  29.     public void onClick(View v) {  
  30.         // TODO Auto-generated method stub  
  31. //将他们都设置为空  
  32.     weight.setText("");  
  33.     height.setText("");  
  34.     detail.setText("");  
  35.     }  
  36. });  
  37. //  获取信息按钮的监听  
  38.    getInfo.setOnClickListener(new View.OnClickListener() {  
  39.       
  40.     @Override  
  41.     public void onClick(View v) {  
  42.         // TODO Auto-generated method stub  
  43.     Intent intent =new  Intent(MainActivity.this, Other.class);//创建意图对象  
  44. //  增加附加信息  
  45. intent.putExtra("weight", Double.valueOf(weight.getText().toString()));  
  46. intent.putExtra("height", Double.valueOf(height.getText().toString()));  
  47. //设置启动并传递请求码  
  48. startActivityForResult(intent, 1);  
  49.       
  50.     }  
  51. });  
  52.     
  53.     }  
  54. //    处理返回的信息  
  55.     @Override  
  56.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  57.         // TODO Auto-generated method stub  
  58.         switch (resultCode) {  
  59.         case RESULT_OK:  
  60.             //设置信息  
  61.             MainActivity.this.detail.setText(data.getStringExtra("endMsg"));  
  62.               
  63.             break;  
  64.   
  65.         default:  
  66.             break;  
  67.         }  
  68.     }  
  69.       
  70. }  
  71. http://blog.renren.com/blog/573785236/934703413
    http://guangzhou.baixing.com/qitafuwu/a417877410.html
    http://club.jd.com/CommunityGroupDetail/13057867_1.html
    http://club.jd.com/CommunityGroupDetail/13057868_1.html
    http://club.jd.com/CommunityGroupDetail/13057869_1.html
    http://club.jd.com/CommunityGroupDetail/13057960_1.html
    http://club.jd.com/CommunityGroupDetail/13057986_1.html
    http://club.jd.com/CommunityGroupDetail/13057988_1.html
    http://club.jd.com/CommunityGroupDetail/13058011_1.html
    http://club.jd.com/CommunityGroupDetail/13058019_1.html
    http://club.jd.com/CommunityGroupDetail/13058020_1.html
    http://club.jd.com/CommunityGroupDetail/13058038_1.html
    http://club.jd.com/CommunityGroupDetail/13058040_1.html
    http://club.jd.com/CommunityGroupDetail/13058045_1.html
    http://club.jd.com/CommunityGroupDetail/13058068_1.html
    http://club.jd.com/CommunityGroupDetail/13058074_1.html
    http://club.jd.com/CommunityGroupDetail/13058079_1.html
    http://club.jd.com/CommunityGroupDetail/13058092_1.html
    http://club.jd.com/CommunityGroupDetail/13058093_1.html
    http://club.jd.com/CommunityGroupDetail/13058096_1.html
    http://club.jd.com/CommunityGroupDetail/13058102_1.html
    http://club.jd.com/CommunityGroupDetail/13058104_1.html
    http://club.jd.com/CommunityGroupDetail/13058105_1.html
    http://club.jd.com/CommunityGroupDetail/13058130_1.html
    http://club.jd.com/CommunityGroupDetail/13058132_1.html
    http://club.jd.com/CommunityGroupDetail/13058133_1.html
    http://club.jd.com/CommunityGroupDetail/13058138_1.html
    http://club.jd.com/CommunityGroupDetail/13058139_1.html
    http://club.jd.com/CommunityGroupDetail/13058140_1.html
    http://club.jd.com/CommunityGroupDetail/13058163_1.html
    http://club.jd.com/CommunityGroupDetail/13058165_1.html
    http://club.jd.com/CommunityGroupDetail/13058170_1.html
    http://club.jd.com/CommunityGroupDetail/13058188_1.html
    http://club.jd.com/CommunityGroupDetail/13058210_1.html
    http://club.jd.com/CommunityGroupDetail/13058220_1.html
    http://club.jd.com/CommunityGroupDetail/13058229_1.html
    http://club.jd.com/CommunityGroupDetail/13058230_1.html
    http://club.jd.com/CommunityGroupDetail/13058241_1.html
    http://club.jd.com/CommunityGroupDetail/13058243_1.html
    http://club.jd.com/CommunityGroupDetail/13058244_1.html
    http://club.jd.com/CommunityGroupDetail/13058249_1.html
    http://club.jd.com/CommunityGroupDetail/13058260_1.html
    http://club.jd.com/CommunityGroupDetail/13058266_1.html
    http://club.jd.com/CommunityGroupDetail/13058274_1.html
    http://club.jd.com/CommunityGroupDetail/13058276_1.html
    http://club.jd.com/CommunityGroupDetail/13058278_1.html
    http://club.jd.com/CommunityGroupDetail/13058280_1.html
    http://club.jd.com/CommunityGroupDetail/13058288_1.html
    http://club.jd.com/CommunityGroupDetail/13058295_1.html
    http://club.jd.com/CommunityGroupDetail/13058299_1.html
    http://club.jd.com/CommunityGroupDetail/13058300_1.html
    http://club.jd.com/CommunityGroupDetail/13058301_1.html
    http://club.jd.com/CommunityGroupDetail/13058305_1.html
    http://club.jd.com/CommunityGroupDetail/13058316_1.html
    http://club.jd.com/CommunityGroupDetail/13058320_1.html
    http://club.jd.com/CommunityGroupDetail/13058322_1.html
    http://club.jd.com/CommunityGroupDetail/13058323_1.html
    http://club.jd.com/CommunityGroupDetail/13058330_1.html
    http://club.jd.com/CommunityGroupDetail/13058338_1.html
    http://club.jd.com/CommunityGroupDetail/13058339_1.html
    http://club.jd.com/CommunityGroupDetail/13058344_1.html
    http://club.jd.com/CommunityGroupDetail/13058351_1.html
    http://club.jd.com/CommunityGroupDetail/13058361_1.html
    http://club.jd.com/CommunityGroupDetail/13058363_1.html
    http://club.jd.com/CommunityGroupDetail/13058365_1.html
    http://club.jd.com/CommunityGroupDetail/13058368_1.html
    http://club.jd.com/CommunityGroupDetail/13058376_1.html
    http://club.jd.com/CommunityGroupDetail/13058378_1.html
    http://club.jd.com/CommunityGroupDetail/13058379_1.html
    http://club.jd.com/CommunityGroupDetail/13058381_1.html
    http://club.jd.com/CommunityGroupDetail/13058392_1.html
    http://club.jd.com/CommunityGroupDetail/13058393_1.html
    http://club.jd.com/CommunityGroupDetail/13058395_1.html
    http://club.jd.com/CommunityGroupDetail/13058400_1.html
    http://club.jd.com/CommunityGroupDetail/13058402_1.html
    http://club.jd.com/CommunityGroupDetail/13058408_1.html
    http://club.jd.com/CommunityGroupDetail/13058416_1.html
    http://club.jd.com/CommunityGroupDetail/13058417_1.html
    http://club.jd.com/CommunityGroupDetail/13058429_1.html
    http://club.jd.com/CommunityGroupDetail/13058435_1.html
    http://club.jd.com/CommunityGroupDetail/13058436_1.html
    http://club.jd.com/CommunityGroupDetail/13058441_1.html
    http://club.jd.com/CommunityGroupDetail/13058442_1.html
    http://club.jd.com/CommunityGroupDetail/13058443_1.html
    http://club.jd.com/CommunityGroupDetail/13058450_1.html
    http://club.jd.com/CommunityGroupDetail/13058460_1.html
    http://club.jd.com/CommunityGroupDetail/13058465_1.html
    http://club.jd.com/CommunityGroupDetail/13058466_1.html
    http://club.jd.com/CommunityGroupDetail/13058469_1.html
    http://club.jd.com/CommunityGroupDetail/13058474_1.html
    http://club.jd.com/CommunityGroupDetail/13058475_1.html
    http://club.jd.com/CommunityGroupDetail/13058481_1.html
    http://club.jd.com/CommunityGroupDetail/13058487_1.html
    http://club.jd.com/CommunityGroupDetail/13058491_1.html
    http://club.jd.com/CommunityGroupDetail/13058493_1.html
    http://club.jd.com/CommunityGroupDetail/13058499_1.html
    http://club.jd.com/CommunityGroupDetail/13058500_1.html
    http://club.jd.com/CommunityGroupDetail/13058502_1.html
    http://club.jd.com/CommunityGroupDetail/13058504_1.html
    http://club.jd.com/CommunityGroupDetail/13058506_1.html
    http://club.jd.com/CommunityGroupDetail/13058508_1.html
    http://club.jd.com/CommunityGroupDetail/13058513_1.html
    http://club.jd.com/CommunityGroupDetail/13058524_1.html
    http://club.jd.com/CommunityGroupDetail/13058526_1.html
    http://club.jd.com/CommunityGroupDetail/13058529_1.html
    http://club.jd.com/CommunityGroupDetail/13058536_1.html
    http://club.jd.com/CommunityGroupDetail/13058537_1.html
    http://club.jd.com/CommunityGroupDetail/13058538_1.html
    http://club.jd.com/CommunityGroupDetail/13058539_1.html
    http://club.jd.com/CommunityGroupDetail/13058542_1.html
    http://club.jd.com/CommunityGroupDetail/13058543_1.html
    http://club.jd.com/CommunityGroupDetail/13058544_1.html
    http://club.jd.com/CommunityGroupDetail/13058549_1.html
    http://club.jd.com/CommunityGroupDetail/13058550_1.html
    http://club.jd.com/CommunityGroupDetail/13058555_1.html
    http://club.jd.com/CommunityGroupDetail/13058559_1.html
    http://club.jd.com/CommunityGroupDetail/13058562_1.html
    http://club.jd.com/CommunityGroupDetail/13058565_1.html
    http://club.jd.com/CommunityGroupDetail/13058567_1.html
    http://club.jd.com/CommunityGroupDetail/13058572_1.html
    http://club.jd.com/CommunityGroupDetail/13058573_1.html
    http://club.jd.com/CommunityGroupDetail/13058576_1.html
    http://club.jd.com/CommunityGroupDetail/13058579_1.html
    http://club.jd.com/CommunityGroupDetail/13058580_1.html
    http://club.jd.com/CommunityGroupDetail/13058595_1.html
    http://club.jd.com/CommunityGroupDetail/13058600_1.html
    http://club.jd.com/CommunityGroupDetail/13058601_1.html
    http://club.jd.com/CommunityGroupDetail/13058602_1.html
    http://club.jd.com/CommunityGroupDetail/13058603_1.html
    http://club.jd.com/CommunityGroupDetail/13058609_1.html
    http://club.jd.com/CommunityGroupDetail/13058613_1.html
    http://club.jd.com/CommunityGroupDetail/13058615_1.html
    http://club.jd.com/CommunityGroupDetail/13058618_1.html
    http://club.jd.com/CommunityGroupDetail/13058621_1.html
    http://club.jd.com/CommunityGroupDetail/13058622_1.html
    http://club.jd.com/CommunityGroupDetail/13058631_1.html
    http://club.jd.com/CommunityGroupDetail/13058636_1.html
    http://club.jd.com/CommunityGroupDetail/13058645_1.html
    http://club.jd.com/CommunityGroupDetail/13058651_1.html
    http://club.jd.com/CommunityGroupDetail/13058658_1.html
    http://club.jd.com/CommunityGroupDetail/13058662_1.html
    http://club.jd.com/CommunityGroupDetail/13058670_1.html
    http://club.jd.com/CommunityGroupDetail/13058671_1.html
    http://club.jd.com/CommunityGroupDetail/13058672_1.html
    http://club.jd.com/CommunityGroupDetail/13058691_1.html
    http://club.jd.com/CommunityGroupDetail/13058692_1.html
    http://club.jd.com/CommunityGroupDetail/13058693_1.html
    http://club.jd.com/CommunityGroupDetail/13058694_1.html
    http://club.jd.com/CommunityGroupDetail/13058695_1.html
    http://club.jd.com/CommunityGroupDetail/13058696_1.html
    http://club.jd.com/CommunityGroupDetail/13058708_1.html
    http://club.jd.com/CommunityGroupDetail/13058719_1.html
    http://club.jd.com/CommunityGroupDetail/13058727_1.html
    http://club.jd.com/CommunityGroupDetail/13058728_1.html
    http://club.jd.com/CommunityGroupDetail/13058732_1.html
    http://club.jd.com/CommunityGroupDetail/13058733_1.html
    http://club.jd.com/CommunityGroupDetail/13058734_1.html
    http://club.jd.com/CommunityGroupDetail/13058736_1.html
    http://club.jd.com/CommunityGroupDetail/13058738_1.html
    http://club.jd.com/CommunityGroupDetail/13058740_1.html
    http://club.jd.com/CommunityGroupDetail/13058743_1.html
    http://club.jd.com/CommunityGroupDetail/13058746_1.html
    http://club.jd.com/CommunityGroupDetail/13058748_1.html
    http://club.jd.com/CommunityGroupDetail/13058751_1.html
    http://club.jd.com/CommunityGroupDetail/13058755_1.html
    http://club.jd.com/CommunityGroupDetail/13058757_1.html
    http://club.jd.com/CommunityGroupDetail/13058760_1.html
    http://club.jd.com/CommunityGroupDetail/13058763_1.html
    http://club.jd.com/CommunityGroupDetail/13058767_1.html
    http://club.jd.com/CommunityGroupDetail/13058770_1.html
    http://club.jd.com/CommunityGroupDetail/13058771_1.html
    http://club.jd.com/CommunityGroupDetail/13058776_1.html
    http://club.jd.com/CommunityGroupDetail/13058784_1.html
    http://club.jd.com/CommunityGroupDetail/13058786_1.html
    http://club.jd.com/CommunityGroupDetail/13058787_1.html
    http://club.jd.com/CommunityGroupDetail/13058792_1.html
    http://club.jd.com/CommunityGroupDetail/13058793_1.html
    http://club.jd.com/CommunityGroupDetail/13058795_1.html
    http://club.jd.com/CommunityGroupDetail/13058797_1.html
    http://club.jd.com/CommunityGroupDetail/13058802_1.html
    http://club.jd.com/CommunityGroupDetail/13058810_1.html
    http://club.jd.com/CommunityGroupDetail/13058813_1.html
    http://club.jd.com/CommunityGroupDetail/13058815_1.html
    http://club.jd.com/CommunityGroupDetail/13058818_1.html
    http://club.jd.com/CommunityGroupDetail/13058823_1.html
    http://club.jd.com/CommunityGroupDetail/13058824_1.html
    http://club.jd.com/CommunityGroupDetail/13058825_1.html
    http://club.jd.com/CommunityGroupDetail/13058828_1.html
    http://club.jd.com/CommunityGroupDetail/13058831_1.html
    http://club.jd.com/CommunityGroupDetail/13058833_1.html
    http://club.jd.com/CommunityGroupDetail/13058835_1.html
    http://club.jd.com/CommunityGroupDetail/13058839_1.html
    http://club.jd.com/CommunityGroupDetail/13058844_1.html
    http://club.jd.com/CommunityGroupDetail/13058848_1.html
    http://club.jd.com/CommunityGroupDetail/13058851_1.html
    http://club.jd.com/CommunityGroupDetail/13058857_1.html
    http://club.jd.com/CommunityGroupDetail/13058858_1.html
    http://club.jd.com/CommunityGroupDetail/13058861_1.html
    http://club.jd.com/CommunityGroupDetail/13058864_1.html
    http://club.jd.com/CommunityGroupDetail/13058869_1.html
    http://club.jd.com/CommunityGroupDetail/13058872_1.html
    http://club.jd.com/CommunityGroupDetail/13058878_1.html
    http://club.jd.com/CommunityGroupDetail/13058879_1.html
    http://club.jd.com/CommunityGroupDetail/13058880_1.html
    http://club.jd.com/CommunityGroupDetail/13058888_1.html
    http://club.jd.com/CommunityGroupDetail/13058890_1.html
    http://club.jd.com/CommunityGroupDetail/13058897_1.html
    http://club.jd.com/CommunityGroupDetail/13058898_1.html
    http://club.jd.com/CommunityGroupDetail/13058900_1.html
    http://club.jd.com/CommunityGroupDetail/13058903_1.html
    http://club.jd.com/CommunityGroupDetail/13058919_1.html
    http://club.jd.com/CommunityGroupDetail/13058923_1.html
    http://club.jd.com/CommunityGroupDetail/13058931_1.html
    http://club.jd.com/CommunityGroupDetail/13058942_1.html
    http://club.jd.com/CommunityGroupDetail/13058945_1.html
    http://club.jd.com/CommunityGroupDetail/13058953_1.html
    http://club.jd.com/CommunityGroupDetail/13058954_1.html
    http://club.jd.com/CommunityGroupDetail/13058958_1.html
    http://club.jd.com/CommunityGroupDetail/13058960_1.html
    http://club.jd.com/CommunityGroupDetail/13058963_1.html
    http://club.jd.com/CommunityGroupDetail/13058979_1.html
    http://club.jd.com/CommunityGroupDetail/13058983_1.html
    http://club.jd.com/CommunityGroupDetail/13058985_1.html
    http://club.jd.com/CommunityGroupDetail/13058986_1.html
    http://club.jd.com/CommunityGroupDetail/13058991_1.html
    http://club.jd.com/CommunityGroupDetail/13058995_1.html
    http://club.jd.com/CommunityGroupDetail/13058997_1.html
    http://club.jd.com/CommunityGroupDetail/13058999_1.html
    http://club.jd.com/CommunityGroupDetail/13059000_1.html
    http://club.jd.com/CommunityGroupDetail/13059004_1.html
    http://club.jd.com/CommunityGroupDetail/13059022_1.html
    http://club.jd.com/CommunityGroupDetail/13059023_1.html
    http://club.jd.com/CommunityGroupDetail/13059032_1.html
    http://club.jd.com/CommunityGroupDetail/13059062_1.html
    http://club.jd.com/CommunityGroupDetail/13059063_1.html
    http://club.jd.com/CommunityGroupDetail/13059064_1.html
    http://club.jd.com/CommunityGroupDetail/13059069_1.html
    http://club.jd.com/CommunityGroupDetail/13059078_1.html
    http://club.jd.com/CommunityGroupDetail/13059080_1.html
    http://club.jd.com/CommunityGroupDetail/13059092_1.html
    http://club.jd.com/CommunityGroupDetail/13059094_1.html
    http://club.jd.com/CommunityGroupDetail/13059095_1.html
    http://club.jd.com/CommunityGroupDetail/13059100_1.html
    http://club.jd.com/CommunityGroupDetail/13059101_1.html
    http://club.jd.com/CommunityGroupDetail/13059108_1.html
    http://club.jd.com/CommunityGroupDetail/13059112_1.html
    http://club.jd.com/CommunityGroupDetail/13059118_1.html
    http://club.jd.com/CommunityGroupDetail/13059119_1.html
    http://club.jd.com/CommunityGroupDetail/13059124_1.html
    http://club.jd.com/CommunityGroupDetail/13059131_1.html
    http://club.jd.com/CommunityGroupDetail/13059141_1.html
    http://club.jd.com/CommunityGroupDetail/13059143_1.html
    http://club.jd.com/CommunityGroupDetail/13059151_1.html
    http://club.jd.com/CommunityGroupDetail/13059158_1.html
    http://club.jd.com/CommunityGroupDetail/13059186_1.html
    http://club.jd.com/CommunityGroupDetail/13059189_1.html
    http://club.jd.com/CommunityGroupDetail/13059195_1.html
    http://club.jd.com/CommunityGroupDetail/13059205_1.html
    http://club.jd.com/CommunityGroupDetail/13059209_1.html
    http://club.jd.com/CommunityGroupDetail/13059210_1.html
    http://club.jd.com/CommunityGroupDetail/13059211_1.html
    http://club.jd.com/CommunityGroupDetail/13059222_1.html
    http://club.jd.com/CommunityGroupDetail/13059230_1.html
    http://club.jd.com/CommunityGroupDetail/13059232_1.html
    http://club.jd.com/CommunityGroupDetail/13059233_1.html
    http://club.jd.com/CommunityGroupDetail/13059240_1.html
    http://club.jd.com/CommunityGroupDetail/13059242_1.html
    http://club.jd.com/CommunityGroupDetail/13059252_1.html
    http://club.jd.com/CommunityGroupDetail/13059267_1.html
    http://club.jd.com/CommunityGroupDetail/13059311_1.html
    http://club.jd.com/CommunityGroupDetail/13059319_1.html
    http://club.jd.com/CommunityGroupDetail/13059320_1.html
    http://club.jd.com/CommunityGroupDetail/13059324_1.html
    http://club.jd.com/CommunityGroupDetail/13059329_1.html
    http://club.jd.com/CommunityGroupDetail/13059342_1.html
    http://club.jd.com/CommunityGroupDetail/13059343_1.html
    http://club.jd.com/CommunityGroupDetail/13059349_1.html
    http://club.jd.com/CommunityGroupDetail/13059356_1.html
    http://club.jd.com/CommunityGroupDetail/13059374_1.html
    http://club.jd.com/CommunityGroupDetail/13059377_1.html
    http://club.jd.com/CommunityGroupDetail/13059381_1.html
    http://club.jd.com/CommunityGroupDetail/13059382_1.html
    http://club.jd.com/CommunityGroupDetail/13059383_1.html
    http://club.jd.com/CommunityGroupDetail/13059408_1.html
    http://club.jd.com/CommunityGroupDetail/13059431_1.html
    http://club.jd.com/CommunityGroupDetail/13059440_1.html
    http://club.jd.com/CommunityGroupDetail/13059496_1.html
    http://club.jd.com/CommunityGroupDetail/13059497_1.html
    http://club.jd.com/CommunityGroupDetail/13059498_1.html
    http://club.jd.com/CommunityGroupDetail/13059522_1.html
    http://club.jd.com/CommunityGroupDetail/13059525_1.html
    http://club.jd.com/CommunityGroupDetail/13059552_1.html
    http://club.jd.com/CommunityGroupDetail/13059611_1.html

Other.java
  1. package com.example.inten3;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. import android.widget.TextView;  
  9.   
  10. public class Other extends Activity {  
  11.     private Button returnMsg, resetbut;  
  12.     private TextView weightMsg, heightMsg;  
  13.     private Double weight, height;  
  14.   
  15.     private String endMsg;  
  16.   
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         // TODO Auto-generated method stub  
  20.         super.onCreate(savedInstanceState);  
  21.         super.setContentView(R.layout.other);  
  22.         returnMsg = (Button) this.findViewById(R.id.Otherbutton1);  
  23.         resetbut = (Button) this.findViewById(R.id.Otherbutton2);  
  24.         weightMsg = (TextView) this.findViewById(R.id.OthertextView1);  
  25.         heightMsg = (TextView) this.findViewById(R.id.OthertextView2);  
  26.         // 获取意图对象  
  27.         Intent intent = super.getIntent();  
  28.         // 获得参数  
  29.         weight = intent.getDoubleExtra("weight", 0);  
  30.         height = intent.getDoubleExtra("height", 0);  
  31.         weightMsg.setText("您的体重:" + weight + "KG");  
  32.         heightMsg.setText("您的身高:" + height + "CM");  
  33.         returnMsg.setOnClickListener(new View.OnClickListener() {  
  34.             // 对传入的数据进项判断和处理  
  35.             @Override  
  36.             public void onClick(View v) {  
  37.                 // TODO Auto-generated method stub  
  38.                 Double heightNum = height / 100;  
  39.                 double endNum = weight / (heightNum * heightNum);  
  40.                 if (endNum >= 18 && endNum <= 25) {  
  41.                     endMsg = "您的身体很正常哦,继续保持亲。";  
  42.                 } else if (endNum < 18) {  
  43.                     endMsg = "亲啊,不能总是减肥啊,您现在可是偏瘦哦,当心身体";  
  44.                 } else if (endNum > 25 && endNum <= 30) {  
  45.                     endMsg = "您现在有一点胖哦,不过不要紧,要注意饮食哦";  
  46.                 } else if (endNum > 30 && endNum <= 35) {  
  47.                     endMsg = "亲,您已经进入肥胖人群 了哦,注意锻炼哦";  
  48.   
  49.                 } else if (endNum > 35) {  
  50.                     endMsg = "额,你,你。。你怎么可以这样,还不赶快减肥,当心找不到对象哦";  
  51.                 }  
  52.                 // 将参数设置到intnet上  
  53.                 Other.this.getIntent().putExtra("endMsg", endMsg);  
  54.                 // 设置返回集,并设置返回接受码  
  55.                 Other.this.setResult(RESULT_OK, Other.this.getIntent());  
  56.                 // 将dangqianActivity结束掉  
  57.                 Other.this.finish();  
  58.             }  
  59.   
  60.         });  
  61.         // 重新输入监听  
  62.         resetbut.setOnClickListener(new View.OnClickListener() {  
  63.   
  64.             @Override  
  65.             public void onClick(View v) {  
  66.                 // TODO Auto-generated method stub  
  67.                 // 设置返回集合取消状态码  
  68.                 Other.this.setResult(RESULT_CANCELED, Other.this.getIntent());  
  69.                 // 结束当前Activity  
  70.                 Other.this.finish();  
  71.             }  
  72.         });  
  73.     }  
  74. }  

bubuko.com,布布扣


bubuko.com,布布扣


bubuko.com,布布扣

学习了intent的基本用途,下节我们来学习Intent调用系统指令来完成一些其他操作


下节预报:Intent进阶

从零开始学android<Intent初步.四十.>

标签:android   style   blog   http   os   io   使用   java   ar   

原文地址:http://www.cnblogs.com/yido9932/p/3963611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!