这次的作业总是有模模糊糊的感觉,上课也有点囫囵吞枣。所以在做这次作业之前看了很多我们班同学的成品,下面是最基本的界面代码
<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>
接下来是主代码
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();