前端XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#CCCCCC"
tools:context="lesson10.computer.app2.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是主界面"
android:layout_margin="8dp"
android:textSize="18sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="参数1"
android:textSize="18sp"
/>
<EditText
android:id="@+id/et_param1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="请输入参数1!"
android:textSize="18sp"
android:textColorHint="@android:color/holo_red_dark"
android:textColor="@android:color/holo_red_dark"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="参数2"
android:textSize="18sp"
/>
<EditText
android:id="@+id/et_param2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="请输入参数2!"
android:textSize="18sp"
android:textColorHint="@android:color/holo_red_dark"
android:textColor="@android:color/holo_red_dark"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="点我跳转"
android:onClick="jumpMethod"
/>
</LinearLayout>
后台代码Main
/**
* 跳转按钮对应的事件处理函数
* @param v
*/
public void jumpMethod(View v){
Intent intent = new Intent(this,JumpActivity.class);
//准备参数
intent.putExtra("param1",et_param1.getText().toString());
intent.putExtra("param2", et_param2.getText().toString());
startActivity(intent);
}
跳转后的画面Jump
接受主界面给的数据
public class JumpActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jump);
textView = (TextView) findViewById(R.id.tv);
Intent intent = this.getIntent();
String strParam1 = intent.getStringExtra("param1");
String strParam2 = intent.getStringExtra("param2");
textView.setText(strParam1+strParam2);
}