作业5
package com.example.tn1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click1(View view){
Intent intent =new Intent(this,SecendActivity.class);
startActivity(intent);
}
}
package com.example.tn1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class SecendActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secend);
}
public void click2(View view){
Intent intent=new Intent();
intent.setAction("com.nn.activity2");
startActivity(intent);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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" tools:context=".MainActivity" > <Button android:id="@+id/btu1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="界面1按钮" android:onClick="click1" /> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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" tools:context=".SecendActivity" > <Button android:id="@+id/btu2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="界面2按钮" android:onClick="click2" /> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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" tools:context=".ThirdActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="界面3" /> </RelativeLayout>
2.
package com.example.charp2;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click1(View view){
Intent intent=new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打开浏览器"
android:onClick="click1" />
</RelativeLayout>
3.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <EditText android:id="@+id/edt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="输入第一个数" android:textSize="25dp" /> <EditText android:id="@+id/edt2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="输入第二个数" android:textSize="25dp" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/btn_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" android:textSize="25dp" android:onClick="click1" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:textSize="25dp" android:onClick="click2" /> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="*" android:textSize="25dp" android:onClick="click3" /> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="/" android:textSize="25dp" android:onClick="click4"/> </LinearLayout> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="结果是" android:textSize="25dp" /> </LinearLayout>
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num1=((EditText)(findViewById(R.id.edt1))).getText().toString();
int n1=Integer.parseInt(num1);
String num2=((EditText)(findViewById(R.id.edt2))).getText().toString();
int n2=Integer.parseInt(num2);
TextView tv1=(TextView) findViewById(R.id.tv1);
int n3=n1+n2;
tv1.setText("答案是"+n3);
}
});
findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num1=((EditText)(findViewById(R.id.edt1))).getText().toString();
int n1=Integer.parseInt(num1);
String num2=((EditText)(findViewById(R.id.edt2))).getText().toString();
int n2=Integer.parseInt(num2);
TextView tv1=(TextView) findViewById(R.id.tv1);
int n3=n1-n2;
tv1.setText(n3);
}
});
findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num1=((EditText)(findViewById(R.id.edt1))).getText().toString();
int n1=Integer.parseInt(num1);
String num2=((EditText)(findViewById(R.id.edt2))).getText().toString();
int n2=Integer.parseInt(num2);
TextView tv1=(TextView) findViewById(R.id.tv1);
int n3=n1*n2;
tv1.setText(n3);
}
});findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num1=((EditText)(findViewById(R.id.edt1))).getText().toString();
int n1=Integer.parseInt(num1);
String num2=((EditText)(findViewById(R.id.edt2))).getText().toString();
int n2=Integer.parseInt(num2);
TextView tv1=(TextView) findViewById(R.id.tv1);
int n3=n1/n2;
tv1.setText(n3);
}
});
}
}


浙公网安备 33010602011771号