安卓作业之页面跳转1

这次的作业总是有模模糊糊的感觉,上课也有点囫囵吞枣。所以在做这次作业之前看了很多我们班同学的成品,下面是最基本的界面代码

 

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/et"

android:hint="@string/xm"

android:layout_marginTop="250dp" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:weightSum="2">

<Button

android:onClick="onClick"

android:id="@+id/pg"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:text="@string/pg"/>

<Button

android:onClick="onClick"

android:id="@+id/tc"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="match_parent"

android:text="@string/tc"/>

</LinearLayout>

<TextView

android:id="@+id/result"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""/>

其次是子界面

<TextView

android:id="@+id/f"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

android:layout_gravity="center"/>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:weightSum="2">

<Button

android:onClick="onClick"

android:id="@+id/y"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="wrap_content"

android:text="@string/y" />

<Button

android:onClick="onClick"

android:id="@+id/n"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="wrap_content"

android:text="@string/n" />

</LinearLayout>

 

接下来是主代码

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

xm = (EditText) findViewById(R.id.et);

result = (TextView)

findViewById(R.id.result);

Intent intent=getIntent();

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

} public void onClick(View view) {

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

switch (view.getId())

{

case R.id.pg: pg();

case R.id.tc:

finish();

break; } } private void pg() {

Intent intent = new Intent(MainActivity.this, Main2.class);

String text = xm.getText().toString();

intent.putExtra("name", text + ":对学习java有没有信心?"); startActivity(intent);

}

}

 

@Override protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main2);

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

Intent intent = getIntent();

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

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

}

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

)

{

case R.id.y: y();

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

}

}

public void y()

{

Intent intent = new Intent(Main2.this,MainActivity.class);

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

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

startActivity(intent);

finish();

}

public void n()

{

Intent intent = new Intent(Main2.this,MainActivity.class);

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

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

startActivity(intent);

finish();

}

}

传递数据

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

页面跳转


Intent intent = new Intent(MainActivity.this, Main2.class);

获取

Intent intent = getIntent(); String yes = y.getText().toString(); intent.putExtra("result","对学习java有信心"); startActivity(intent); finish();

 

转载于:https://www.cnblogs.com/hero-c/p/6727498.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值