zoukankan      html  css  js  c++  java
  • 第四次作业

    要求:

    1.输入两个数,当点击单选钮(加减乘除)的时候,在下面的TextView中显示对应的计算结果。

    2.button按钮是清空,作用是清空两个edittext和TextView中的内容。

    3.需要提交layout代码和activity的代码。此外还需要运行截图。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        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:background="#03A9F4">
        <LinearLayout
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="150dp"
            android:layout_marginLeft="30sp"
            android:layout_marginRight="30sp"
            android:background="#E9E0E0">
    
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="请输入第一个数:"
                android:textSize="20sp"
                />
            <EditText
                android:id="@+id/one"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:numeric="integer"
                android:text="0"
                />
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/line2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/line1"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="30sp"
            android:layout_marginRight="30sp"
            android:orientation="horizontal">
    
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="请输入第二个数:"
                android:textSize="20sp"
                android:background="#E7DFDF"
    
                />
            <EditText
                android:id="@+id/two"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:background="#FFFFFF"
                android:numeric="integer"
                android:text="0"/>
        </LinearLayout>
    
        <RadioGroup
            android:id="@+id/rg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/line2"
            android:layout_marginTop="40dp"
            android:background="#EEEEEE"
            android:orientation="horizontal">
            <RadioButton
                android:id="@+id/jia"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+"
                android:layout_weight="1"
                android:textSize="30sp"
                />
            <RadioButton
                android:id="@+id/jian"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="--"
                android:layout_weight="1"
                android:textSize="30sp"
                />
            <RadioButton
                android:id="@+id/ch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="X"
                android:layout_weight="1"
                android:textSize="30sp"
                />
            <RadioButton
                android:id="@+id/chu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="/"
                android:layout_weight="1"
                android:textSize="30sp"
                />
        </RadioGroup>
        <TextView
            android:id="@+id/jg"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginLeft="30sp"
            android:layout_marginRight="30sp"
            android:layout_below="@+id/rg"
            android:layout_marginTop="40dp"
            android:background="#EEEEEE"
            />
        <Button
            android:id="@+id/qk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="清空"
            android:textSize="30sp"
            android:background="#F44336"
            android:layout_below="@+id/jg"
     1 package com.example.ft;
     2 
     3 import android.os.Bundle;
     4 import android.view.View;
     5 import android.widget.EditText;
     6 import android.widget.RadioGroup;
     7 import android.widget.TextView;
     8 import android.widget.Toast;
     9 
    10 import androidx.appcompat.app.AppCompatActivity;
    11 public class MainActivity extends AppCompatActivity  {
    12     public RadioGroup radioGroup;
    13     EditText one1;
    14     EditText two1;
    15     TextView jg;
    16     Integer d1;
    17     Integer d2;
    18     @Override
    19     protected void onCreate(Bundle savedInstanceState) {
    20         super.onCreate(savedInstanceState);
    21         setContentView(R.layout.activity_main);
    22         radioGroup=findViewById(R.id.rg);
    23         radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    24             @Override
    25             public void onCheckedChanged(RadioGroup radioGroup, int i) {
    26                 switch (i){
    27                     case R.id.jia:jia();break;
    28                     case R.id.jian:jian();break;
    29                     case R.id.ch:ch();break;
    30                     case R.id.chu:chu();break;
    31 
    32                 }
    33 
    34             }
    35         });
    36     }
    37 
    38     private void chu() {
    39         jg= findViewById(R.id.jg);
    40         one1= findViewById(R.id.one);
    41         two1= findViewById(R.id.two);
    42         String on=one1.getText().toString();
    43         String tw=two1.getText().toString();
    44         d1=Integer.valueOf(on);
    45         d2=Integer.valueOf(tw);
    46         if (d2==0||d1==0){
    47             Toast.makeText(MainActivity.this,"除数不能为0",Toast.LENGTH_SHORT).show();
    48         }else {
    49             String st = Integer.toString(d1/d2);
    50             jg.setText(st);
    51         }
    52     }
    53 
    54     private void ch() {
    55         jg= findViewById(R.id.jg);
    56         one1= findViewById(R.id.one);
    57         two1= findViewById(R.id.two);
    58         String on=one1.getText().toString();
    59         String tw=two1.getText().toString();
    60         d1=Integer.valueOf(on);
    61         d2=Integer.valueOf(tw);
    62         String st = Integer.toString(d2*d1);
    63         jg.setText(st);
    64     }
    65 
    66     private void jian() {
    67         jg= findViewById(R.id.jg);
    68         one1= findViewById(R.id.one);
    69         two1= findViewById(R.id.two);
    70         String on=one1.getText().toString();
    71         String tw=two1.getText().toString();
    72         d1=Integer.valueOf(on);
    73         d2=Integer.valueOf(tw);
    74         String st = Integer.toString(d1-d2);
    75         jg.setText(st);
    76     }
    77 
    78     private void jia() {
    79         jg= findViewById(R.id.jg);
    80         one1= findViewById(R.id.one);
    81         two1= findViewById(R.id.two);
    82         String on=one1.getText().toString();
    83         String tw=two1.getText().toString();
    84         d1=Integer.valueOf(on);
    85         d2=Integer.valueOf(tw);
    86         String st = Integer.toString(d2+d1);
    87         jg.setText(st);
    88 
    89     }
    90 
    91     public void qkz(View view) {
    92         jg.setText("");
    93         one1.setText("");
    94         two1.setText("");
    95     }
    96 
    97 
    98 }
    
    
    
    
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30sp"
            android:onClick="qkz"
            />
    </RelativeLayout>
  • 相关阅读:
    如何只通过Sandboxed Solution启动一个定时执行的操作
    创建与SharePoint 2010风格一致的下拉菜单 (续) 整合Feature Custom Action框架
    创建与SharePoint 2010风格一致的下拉菜单
    《SharePoint 2010 应用程序开发指南》第二章预览
    SharePoint 2013 App 开发 (1) 什么是SharePoint App?
    使用Jscex增强SharePoint 2010 JavaScript Client Object Model (JSOM)
    搜索范围的管理
    SharePoint 2010 服务应用程序(Service Application)架构(1)
    SharePoint 2010 服务应用程序(Service Application)架构(2)
    SharePoint 2013 App 开发 (2) 建立开发环境
  • 原文地址:https://www.cnblogs.com/zz2333/p/11574078.html
Copyright © 2011-2022 走看看