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

    <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" >
    
        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="文本信息"
            android:textColor="#FFF79E38"
            android:textSize="25sp"
            android:gravity="center"
            android:textStyle="italic"/>
        
        
        <EditText
            android:id="@+id/et1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv1"
          />
         <EditText
            android:id="@+id/et2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/et1"
             
          />
         
           <TextView
            android:id="@+id/tv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            android:layout_below="@id/et2" 
            android:text="显示计算结果"
            android:gravity="center"
            android:textStyle="italic"/>
        
         <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/tv1"
            android:text="+"
            android:textColor="#FFF79E38"
            android:textSize="25sp"
            android:gravity="center"
            android:textStyle="italic"   
            android:onClick="click"   
            />
         
           <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/btn1"
            android:text="-"
            android:textColor="#FFF79E38"
            android:textSize="25sp"
            android:gravity="center"
            android:textStyle="italic"   
            android:onClick="click"  
            />
    
    
    </RelativeLayout>
    package com.example.q;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        public void click(View v) {
            TextView tv2 = (TextView) findViewById(R.id.tv2);
            EditText et1 = (EditText) findViewById(R.id.et1);
            EditText et2 = (EditText) findViewById(R.id.et2);
            
            int num1,num2,result=0;
            num1=Integer.parseInt(et1.getText().toString());
            num2=Integer.parseInt(et2.getText().toString());
            
            switch (v.getId()) {
            case R.id.btn1:
                result=num1+num2;
                break;
            case R.id.btn2:
                result=num1-num2;
                break;
            }
            tv2.setText(result+"");
        }
    
    }

  • 相关阅读:
    坑爹的 Segmentation fault
    静态全局变量得初始化
    新冠肺炎的感受
    \r和\n的区别
    程序里面带有浮点数,默认会自动转换为double类型存储
    Relativity : Fictitious forces
    Biology 04: The Senses
    156 TCP协议的三次握手和四次挥手
    155 大白话OSI七层协议
    154 互联网和互联网的组成
  • 原文地址:https://www.cnblogs.com/qq-77/p/13743035.html
Copyright © 2011-2022 走看看