Android onActivityResult传值

  1. public   class  Wizard  extends  Activity {  
  2.   
  3.     private  TextView step1result, step2result, step3result;  
  4.   
  5.     public   static   final  String INTENT_STEP1 =  "com.novoda.STEP1" ;  
  6.     public   static   final  String INTENT_STEP2 =  "com.novoda.STEP2" ;  
  7.     public   static   final  String INTENT_STEP3 =  "com.novoda.STEP3" ;  
  8.   
  9.     private   static   final   int  STEP1 =  1 ;  
  10.     private   static   final   int  STEP2 =  2 ;  
  11.     private   static   final   int  STEP3 =  3 ;  
  12.   
  13.     @Override   
  14.     public   void  onCreate(Bundle savedInstanceState) {  
  15.         super .onCreate(savedInstanceState);  
  16.         setContentView(R.layout.wizard);  
  17.           
  18.         this .step1result = (TextView)findViewById(R.id.step1result);  
  19.         this .step2result = (TextView)findViewById(R.id.step2result);  
  20.         this .step3result = (TextView)findViewById(R.id.step3result);    
  21.           
  22.         startActivityForResult(new  Intent(Wizard.INTENT_STEP1), STEP1);          
  23.     }  
  24.       
  25.       
  26.     protected   void  onActivityResult( int  requestCode,  int  resultCode, Intent data) {  
  27.         switch  (requestCode) {  
  28.             case  STEP1:  
  29.                 this .step1result.setText(data.getStringExtra( "STEP1RESULT" ));  
  30.                 startActivityForResult(new  Intent(Wizard.INTENT_STEP2), STEP2);      
  31.                 break ;  
  32.             case  STEP2:  
  33.                 this .step2result.setText(data.getStringExtra( "STEP2RESULT" ));  
  34.                 startActivityForResult(new  Intent(Wizard.INTENT_STEP3), STEP3);      
  35.                 break ;  
  36.             case  STEP3:  
  37.                 this .step3result.setText(data.getStringExtra( "STEP3RESULT" ));  
  38.                 break ;  
  39.         }  
  40.     }  

  1. public   class  Step1  extends  Activity {  
  2.   
  3.     @Override   
  4.     public   void  onCreate(Bundle savedInstanceState) {  
  5.         super .onCreate(savedInstanceState);  
  6.         setContentView(R.layout.step1);  
  7.   
  8.         Button nextStep = (Button)findViewById(R.id.goto2);  
  9.         nextStep.setOnClickListener(new  View.OnClickListener() {  
  10.             public   void  onClick(View v) {  
  11.                 Intent it = new  Intent();  
  12.                 it.putExtra("STEP1RESULT" , ((EditText)findViewById(R.id.step1value)).getText()  
  13.                         .toString());  
  14.                 setResult(Activity.RESULT_OK, it);  
  15.                 finish();  
  16.             }  
  17.         });  
  18.     }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值