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

    <LinearLayout 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:orientation="vertical"
        android:background="#e7e7e7"
        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="com.example.jsj.MainActivity" >
    
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:text="输入第一个数"
                    android:layout_marginTop="20dp"/>
                <EditText
                    android:id="@+id/one"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:background="#ffffff"
                    android:layout_weight="2"
                    android:layout_marginTop="20dp">
                </EditText>
            </LinearLayout>
    
            <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            >
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:text="输入第二个数"
                    android:layout_marginTop="20dp"/>
                <EditText
                    android:id="@+id/twe"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:background="#ffffff"
                    android:layout_weight="2"
                    android:layout_marginTop="20dp">
                </EditText>
              </LinearLayout>
        </LinearLayout>
           <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            >
                    <LinearLayout 
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    >
                 <RadioGroup
                    android:id="@+id/rag"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    >
                <RadioButton 
                    android:id="@+id/but_one"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="25dp"
                    android:layout_weight="1"
                    android:text="+"
                    />
                <RadioButton 
                    android:id="@+id/but_twe"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="25dp"
                    android:layout_weight="1"
                    android:text="—"
                    />
                 <RadioButton 
                    android:id="@+id/but_three"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="25dp"
                    android:layout_weight="1"
                    android:text="*"
                    />
                 <RadioButton 
                    android:id="@+id/but_four"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="25dp"
                    android:layout_weight="1"
                    android:text="/"
                    />
                  </RadioGroup> 
                   </LinearLayout>
                    <RelativeLayout 
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    >
                   <TextView 
                       android:id="@+id/text_one"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:textSize="25dp"
                       android:text="计算机结果显示在这"
                       android:layout_centerInParent="true"
                       />
                   </RelativeLayout>
                   </LinearLayout>
                   <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                       > 
                       <Button 
                           android:id="@+id/but_five"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_centerInParent="true"
                           android:text="清空"/>
                       </RelativeLayout>
                   
    
    </LinearLayout>
    package com.example.jsj;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RadioGroup;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
         EditText shuone;
         EditText shutwe;
         RadioGroup rag;
         Button but_five;
         TextView jg;
          int Result=0;
          int shuone1=0;
          int shutwe1=0;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            shuone = (EditText) findViewById(R.id.one);
            shutwe = (EditText) findViewById(R.id.twe);
            rag = (RadioGroup) findViewById(R.id.rag);
            jg = (TextView) findViewById(R.id.text_one);
            but_five = (Button) findViewById(R.id.but_five);
            rag.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                     shuone1= Integer.parseInt(shuone.getText().toString().trim());
                     shutwe1= Integer.parseInt(shutwe.getText().toString().trim());
                    // TODO Auto-generated method stub
                    if(checkedId==R.id.but_one) {
                        String a= shuone1+shutwe1+"";
                    jg.setText(a);
                }
                    if(checkedId==R.id.but_twe) {
                        String a= shuone1-shutwe1+"";
                    jg.setText(a);
                }
                    if(checkedId==R.id.but_three) {
                        String a= shuone1*shutwe1+"";
                    jg.setText(a);
                }
                    if(checkedId==R.id.but_four) {
                        String a= shuone1/shutwe1+"";
                    jg.setText(a);
                }
                    }
            });
            but_five.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View view) {
                    // TODO Auto-generated method stub
                    jg.setText(null);
                    shuone.setText(null);
                    shutwe.setText(null);
                }
            });
            
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }

  • 相关阅读:
    Windows下不能启动mysql服务错误总结
    使用NSOperationQueue简化多线程开发(转)
    “四人帮”的设计模式经得起时间的考验么?(转)
    ObjectiveC category
    svn add 输出 A (bin) (转)
    NSNotification学习笔记
    浅析UITableViewCell的工作机制
    关于git分支的使用
    delegate使用方法之assign
    ARC(Automatic Reference Counting )技术概述(转)
  • 原文地址:https://www.cnblogs.com/zqxxx/p/11523026.html
Copyright © 2011-2022 走看看