码迷,mamicode.com
首页 > 其他好文 > 详细

一、二周冲刺总结

时间:2015-06-03 15:36:21      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:

由于刚接触android-app的开发,很多问题都解决不了,连搭建环境都花了一个多星期才能解决,所以用了两周才完成了第一个Spring计划,在此要感谢大为同学的帮助才解决了环境的搭建。

技术分享
package com.example.szys;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    
    Button start;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        start=(Button) findViewById(R.id.button1);
        start.setOnClickListener(new Button.OnClickListener(){
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(MainActivity.this, CalActivity.class); 
                startActivity(intent);
            }
        });
    }
}
MainActivity
技术分享
package com.example.szys;

import java.math.*;
import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CalActivity extends Activity {
    int op;
    int a;
    int b;
    int n=0;
    String r;
    Double answer,respon;
    TextView textview1,textview2;
    EditText editText;
    Button button;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.cal_main);
         textview1=(TextView)findViewById(R.id.textView1);
         textview2=(TextView)findViewById(R.id.textView2);
         editText=(EditText)findViewById(R.id.EditText1);
             a =new Random().nextInt(100);
            b =new Random().nextInt(100);
            op=new Random().nextInt(4);
            switch(op)
            {
            case 0:
                textview1.setText(a+"+"+b+"=");
                answer=(double) (a+b);
                break;
            case 1:
                textview1.setText(a+"-"+b+"=");
                answer=(double) (a-b);
                break;
            case 2:
                textview1.setText(a+"*"+b+"=");
                answer=(double) (a*b);
                break;
            case 3:
                while(b==0){
                    b =new Random().nextInt(100);
                }
                textview1.setText(a+"/"+b+"=");
                BigDecimal   x   =   new   BigDecimal((double)a/b);  
                answer  =   x.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();  
                
                break;
            }
            button=(Button)findViewById(R.id.button4);
            button.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    respon=Double.parseDouble(editText.getText().toString());
                    r=textview1.getText().toString();
                    editText.setText("");
                    n++;
                    if(respon.equals(answer))
                    {
                        textview2.setText("你答对了!");
                    }
                    else{
                        textview2.setText("你答错了!\n"+r+answer);
                    }
                    if(n<5)
                    {
                        a =new Random().nextInt(100);
                        b =new Random().nextInt(100);
                        op=new Random().nextInt(4);
                        switch(op)
                        {
                        case 0:
                            textview1.setText(a+"+"+b+"=");
                            answer=(double) (a+b);
                            break;
                        case 1:
                            textview1.setText(a+"-"+b+"=");
                            answer=(double) (a-b);
                            break;
                        case 2:
                            textview1.setText(a+"*"+b+"=");
                            answer=(double) (a*b);
                            break;
                        case 3:
                            while(b==0){
                                b =new Random().nextInt(100);
                            }
                            textview1.setText(a+"/"+b+"=");
                            BigDecimal   x   =   new   BigDecimal((double)a/b);  
                            answer  =   x.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();  
                            
                            break;
                        }
                    }
                }
                
            });

     }
}
CalActivity
技术分享
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="center">
        
        <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="开始" />

            <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="关于" />

            <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="退出" />

    </LinearLayout>

    

</FrameLayout>
activity_main
技术分享
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
       android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="center">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="93dp"
                android:layout_height="wrap_content"
                android:editable="true"
                android:text="" />

            <EditText
                android:id="@+id/EditText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:digits="1234567890.-"
                android:ems="10"
                android:numeric="decimal"
                android:text="" >

                <requestFocus />
            </EditText>
        </LinearLayout>

        <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="确定" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:editable="true"
            android:text="" />
        
    </LinearLayout>

</LinearLayout>
cal_main

技术分享

技术分享

技术分享

技术分享

技术分享

一、二周冲刺总结

标签:

原文地址:http://www.cnblogs.com/wuzijian/p/4549073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!