第一个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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.administrator.myapplication.MainActivity"><EditText
android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:hint="请输入姓名" android:textSize="20sp" android:id="@+id/xm_text" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="166dp"/><LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content"><Button
android:layout_width="20dp" android:layout_height="50dp" android:layout_weight="1" android:text="进入评估" android:textSize="25sp" android:background="#469" android:id="@+id/bt_pg" android:onClick="onClick"/><Button
android:layout_weight="1" android:layout_width="20dp" android:layout_height="50dp" android:text="退出" android:textSize="25sp" android:background="#469" android:id="@+id/bt_tc" android:onClick="Exit"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/yf_tv" android:textColor="@android:color/black" android:layout_margin="30sp" android:layout_weight="0.42" /></LinearLayout>
第二个xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent" android:weightSum="1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textSize="25sp" android:textColor="#000000" android:id="@+id/yf_text2" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="166dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#000000" android:id="@+id/yf_text1" /><LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="有" android:textSize="25sp" android:id="@+id/bt_yes" android:onClick="onClick"/><Button
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:text="没有" android:id="@+id/bt_no" android:onClick="onClick"/> </LinearLayout></LinearLayout>
第一个xml的javapackage com.example.administrator.myapplication;import android.content.Intent;
import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends AppCompatActivity {
private EditText xm_text;
private Button bt_pg,bt_tc; private TextView yftv;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); xm_text=(EditText)findViewById(R.id.xm_text); bt_pg=(Button)findViewById(R.id.bt_pg); bt_tc=(Button)findViewById(R.id.bt_tc);String data="";
Intent intent=getIntent(); String jg=intent.getStringExtra("result"); TextView yftv=(TextView)findViewById(R.id.yf_tv); data = jg; yftv.setText(data);
}
public void onClick(View view) {
switch (view.getId()) { case R.id.bt_pg: PG(); case R.id.xm_text: case R.id.bt_tc: finish(); break; } }
private void PG() {
Intent intent = new Intent(MainActivity.this, Main.class); String text =xm_text.getText().toString(); intent.putExtra("name",text+"同学:有没有信心学好安卓?"); startActivity(intent); } }第二个xml的javapackage com.example.administrator.myapplication;import android.content.Intent;
import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends AppCompatActivity {
private EditText xm_text;
private Button bt_pg,bt_tc; private TextView yftv;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); xm_text=(EditText)findViewById(R.id.xm_text); bt_pg=(Button)findViewById(R.id.bt_pg); bt_tc=(Button)findViewById(R.id.bt_tc);String data="";
Intent intent=getIntent(); String jg=intent.getStringExtra("result"); TextView yftv=(TextView)findViewById(R.id.yf_tv); data = jg; yftv.setText(data);
}
public void onClick(View view) {
switch (view.getId()) { case R.id.bt_pg: PG(); case R.id.xm_text: case R.id.bt_tc: finish(); break; } }
private void PG() {
Intent intent = new Intent(MainActivity.this, Main.class); String text =xm_text.getText().toString(); intent.putExtra("name",text+"同学:有没有信心学好安卓?"); startActivity(intent); } }