实现Intent页面跳转与参数的传递
操作方法
- 01
新建一个FirstAvtivity.javapackage com.zhuguangwei;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;public class FirstActivity extends Activity {private Button myButton;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);myButton = (Button) findViewById(R.id.myButton);myButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent();//Intent传递参数intent.putExtra("testIntent", "123");intent.setClass(FirstActivity.this, SecondActivity.class);FirstActivity.this.startActivity(intent);}});}}新建第二个SecondActivity.javapackage com.zhuguangwei;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.widget.TextView;public class SecondActivity extends Activity{private TextView myTextView;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.other);//使用Intent对象得到FirstActivity传递来的参数Intent intent = getIntent();String value = intent.getStringExtra("testIntent");myTextView = (TextView) findViewById(R.id.myTextView);myTextView.setText(value);}}两个Activity都要在AndroidMenifest.xml中注册事物的本身并不影响人,人们只受对事物看法的影响。人生成败关键在于心态,学习语言心态特别重要,碰到任何问题都不要影响自己的心态。