23.Intent traditional values, Bundle packet transfer value

package com.example.p85;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;


public class MainActivity extends Activity {

    //选择的代表版本的radiobutton
    private RadioButton rb_1,rb_2,rb_3; 
    private Button bt_submit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Super .onCreate (savedInstanceState); 
        setContentView (R.layout.lin); 
    
        // find the controls concerned 
        bt_submit = (the Button) findViewById (R.id.bt_submit); 
        Rb_1 = (the RadioButton) findViewById (R.id.rb1); 
        RB_2 = (the RadioButton) the findViewById (R.id.rb2); 
        rb_3 = (the RadioButton) the findViewById (R.id.rb3); 
      
        bt_submit.setOnClickListener ( new new OnClickListener to () { 
            
            @Override 
            public  void the onClick (View the arg0) {
                 // the TODO Method, Stub-Generated Auto 
                
    // ????????? placeholder here represent what
                II = the Intent new new the Intent (the MainActivity. The this , SECOND. Class ); 
                
                
                the Bundle myBundle = new new the Bundle (); 
                
                
                // determines which one is selected, is determined using the intent to transmit data to the completion of the second 
                IF (rb_1.isChecked ()) {
                 / / ii.putExtra ( "Data", (String) rb_1.getText () toString ().); 
                myBundle.putString ( "Data" , (String) rb_1.getText () toString ().); 
                
                } the else  IF (RB_2 .isChecked ()) {
                 // ii.putExtra ( "Data", (String) rb_2.getText () toString ());.     
                myBundle.putString ( "Data", (String)rb_2.getText().toString());
                }else if (rb_3.isChecked()) {
                //ii.putExtra("data", (String)rb_3.getText().toString());    
                myBundle.putString("data", (String)rb_3.getText().toString());
                }else {
                //ii.putExtra("data", "null");    
                }
                
                ii.putExtras(myBundle);
                
                startActivity(ii);
            }
        });
    }
    
    


    
}

 

 

package com.example.p85;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.IInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class second extends Activity{

    private TextView tv;
    private Button bt;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Auto-Generated Method Stub the TODO 
        Super .onCreate (savedInstanceState); 
        the setContentView (R.layout.lin2); 
        
        BT = (the Button) the findViewById (R.id.bu_back); 
        TV = (the TextView) the findViewById (R.id.tv_receive); 
        
        // receiving a first transmission to the intended activity in 
        the intent My = the this .getIntent (); 
        
        // get the bundle package intent with 
        the bundle mmBundle = my.getExtras (); 
        
        // use the bundle to get the data packet 
        mmBundle.getString SS1 = String ( "data" ); 
        
        // use intention to get data 
        String = my.getStringExtra SS ( "data" ); 
        
        IF ( "".equals (SS1)) { 
            tv.setText ( "no content" ); 
        } the else { 
            tv.setText (SS1 + "is selected" );     
        } 
        
        
        
        bt.setOnClickListener ( new new OnClickListener to () { 
            
            @Override 
            public  void the onClick (View the arg0) {
                 // the TODO Auto-Generated Method Stub 
                
                // jump back may be off by the current activity Finish 
                Finish (); 
                
            } 
        }); 
    } 
    
}

Guess you like

Origin www.cnblogs.com/gzyx/p/12089252.html