安卓作业跳转
界面
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"
android:id="@+id/textv2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/btn3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn3"
android:onClick="onclick"/>
<Button
android:id="@+id/btn4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn4"
android:onClick="onclick"/>
</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_pinggu"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.messi.tiaozhuanapplication.pingguActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/wenti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:textAlignment="center"
android:layout_marginTop="200dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_yes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/btn_yes"
android:textSize="30dp"
android:onClick="onClick"/>
<Button
android:id="@+id/btn_no"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/btn_no"
android:textSize="30dp"
android:onClick="onClick" />
</LinearLayout>
</LinearLayout>
JAVA代码
package com.example.messi.tiaozhuanapplication;
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.TextView;
public class pingguActivity extends AppCompatActivity {
private TextView wenti;
private Button btn_yes;
private Button btn_noe
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pinggu);
wenti = (TextView)findViewById(R.id.wenti);
btn_yes = (Button)findViewById(R.id.btn_yes);
btn_no = (Button)findViewById(R.id.btn_no);
String data="";
Intent intent=getIntent();
String jg=intent.getStringExtra("name");
TextView question=(TextView)findViewById(R.id.wenti);
data = jg;
question.setText(data);
}
public void onClick(View view){
switch (view.getId()){
case R.id.btn_yes:
result1();
break;
case R.id.btn_no:
result2();
break;
}
}
private void result2() {
Intent intent = new Intent();
intent.setClass(pingguActivity.this,Tiaozhuan.class);
String btn2=btn_no.getText().toString();
intent.putExtra("result","评估结果:"+btn2);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
private void result1() {
Intent intent = new Intent();
intent.setClass(pingguActivity.this,Tiaozhuan.class);
String btn1=btn_yes.getText().toString();
intent.putExtra("result","评估结果:"+btn1);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}