多Activity应用

第一个界面
<?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_liyuan"
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"
android:orientation="vertical"
>
<EditText
android:id="@+id/shuru"
android:layout_marginTop="180dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="请输入姓名"></EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/in"
android:onClick="onClick"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="进入评估"
/>
<Button
android:id="@+id/out"
android:onClick="onClick"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="退出" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>



第二个界面相应代码
<?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_gou"
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"
android:gravity="center"
android:orientation="vertical"
tools:context="lenovo_com.liyuan.GouActivity">

<TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="gou同学:学习安卓有没有信心"
android:textSize="20sp"
android:gravity="center"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/shuru2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" "/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:onClick="onClick"
android:id="@+id/no"
android:layout_marginTop="20dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="没有"
android:layout_weight="1"/>
<Button
android:onClick="onClick"
android:id="@+id/yes"
android:layout_marginTop="20dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="有"
android:layout_weight="1"/>




</LinearLayout>
</LinearLayout>


对其功能的实现一

package lenovo_com.liyuan;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



public class LiyuanActivity extends AppCompatActivity {
private EditText shuru;
private Button btn;
private Button in;
private Button out;
private TextView tv1;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liyuan);


shuru= (EditText) findViewById(R.id.shuru);

tv1 = (TextView)

findViewById(R.id.tv1);

Intent intent=getIntent();

tv1.setText(intent.getStringExtra("data"));

} public void onClick(View view) {

String name = shuru.getText().toString();

}
}

package lenovo_com.liyuan;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import static android.R.attr.y;
import static lenovo_com.liyuan.R.id.no;
import static lenovo_com.liyuan.R.id.shuru2;

public class GouActivity extends AppCompatActivity {
private EditText shuru2;
private Button no;
private Button yes;
private TextView question;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_gou);

question = (TextView) findViewById(R.id.question);

Intent intent = getIntent();

String name = intent.getStringExtra("name");

question.setText(name + ":" + "对学习java有没有信心?");

}

public void onClick(View view){ switch (view.getId()

)

{

case R.id.yes: y();

break; case R.id.no: n(); break;

}

}

public void y()

{

Intent intent = new Intent(GouActivity.this,GouActivity.class);

String yes = y.getext().toString();

intent.putExtra("result","对学习java有信心");

startActivity(intent);

finish();

}

public void n()

{

Intent intent = new Intent(GouActivity.this,GouActivity.class);

String no= no.getText().toString();

intent.putExtra("question","对学习java没有信心");

startActivity(intent);

finish();

}

}
第二个Java语句不管怎么改还是有错。。。

 




posted on 2017-04-17 23:00  李美丽1988  阅读(161)  评论(1编辑  收藏  举报

导航