Andriod带参跳转

传值FiveActivity.java    接收SixActivity.java

activity_five.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test4.SixActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:id="@+id/et1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="姓名"/>
        <EditText
            android:id="@+id/et2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="手机号"/>
        <EditText
            android:id="@+id/et3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="地址"/>
        <Button
            android:id="@+id/btn1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="提交"/>

    </LinearLayout>
</RelativeLayout>

FiveActivity.java

package com.example.test4;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class FiveActivity extends Activity {

	EditText et_1=(EditText)findViewById(R.id.et1);
	EditText et_2=(EditText)findViewById(R.id.et2);
	EditText et_3=(EditText)findViewById(R.id.et3);
	Button btn1 = (Button) findViewById(R.id.btn1);  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_five);
        btn1.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View view) {  
              String et1 = (et_1).getText().toString();  
              String et2 = (et_2).getText().toString();  
              String et3 = (et_3).getText().toString();  
              Intent intent = new Intent(FiveActivity.this,SixActivity.class);  
              Bundle bundle= new Bundle();  
              bundle.putString("et1",et1);  
              bundle.putString("et2",et2);  
              bundle.putString("et3",et3);  
              intent.putExtras(bundle);  
              startActivity(intent);  
            }  
        });  

    }
}

activity_six.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test4.SixActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/tv2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/tv3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

</RelativeLayout>

SixActivity.java

package com.example.test4;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class SixActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_six);
		Bundle bundle = this.getIntent().getExtras();
		TextView tv1 = (TextView) findViewById(R.id.tv1);
		TextView tv2 = (TextView) findViewById(R.id.tv2);
		TextView tv3 = (TextView) findViewById(R.id.tv3);
		tv1.setText(bundle.getString("et1"));
		tv2.setText(bundle.getString("et2"));
		tv3.setText(bundle.getString("et3"));

	}
}
原博客地址: 点击打开链接


猜你喜欢

转载自blog.csdn.net/elice_/article/details/80636454
今日推荐