团队成员:陈淑筠、杨家安、陈曦

团队选题:小学四则运算APP

这次发布的是我们APP的最终版本!图片背景有根据用户需求改变!还增加了草稿纸运算的画布功能!

运行结果如下:

 1 package com.example.calculator;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.content.Intent;
 6 import android.view.Menu;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.widget.Button;
10 
11 public class MainActivity extends Activity {
12     
13     private Button xunlian;
14     private Button panduan;
15     private Button xuanze;
16     
17     @Override
18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         setContentView(R.layout.activity_main);
21         xunlian=(Button)findViewById(R.id.button1);
22         panduan=(Button)findViewById(R.id.button4);
23         xuanze=(Button)findViewById(R.id.button2);
24         xunlian.setOnClickListener(new OnClickListener() {//填空题
25             
26             @Override
27             public void onClick(View arg0) {
28                 // TODO Auto-generated method stub
29                 Intent intent=new Intent();
30                 intent.setClass(MainActivity.this, CalculatorSet.class);
31                 startActivity(intent);
32                 MainActivity.this.finish();
33             }
34         });
35         panduan.setOnClickListener(new OnClickListener() {//判断题
36             
37             @Override
38             public void onClick(View arg0) {
39                 // TODO Auto-generated method stub
40                 Intent intent2=new Intent();
41                 intent2.setClass(MainActivity.this,panduanset.class);
42                 startActivity(intent2);
43                 MainActivity.this.finish();
44             }
45         });
46         xuanze.setOnClickListener(new OnClickListener() {
47             
48             @Override
49             public void onClick(View arg0) {
50                 // TODO Auto-generated method stub
51                 Intent intent3=new Intent();
52                 intent3.setClass(MainActivity.this, ChoiceSet.class);
53                 startActivity(intent3);
54                 MainActivity.this.finish();
55             }
56         });
57     }
58 
59     @Override
60     public boolean onCreateOptionsMenu(Menu menu) {
61         // Inflate the menu; this adds items to the action bar if it is present.
62         getMenuInflater().inflate(R.menu.main, menu);
63         return true;
64     }
65 
66 }
MainActivity.java
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:background="@drawable/lovely3"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context=".MainActivity" >
11 
12     <TextView
13         android:id="@+id/textView2"
14         android:layout_width="wrap_content"
15         android:layout_height="wrap_content"
16         android:layout_alignParentTop="true"
17         android:layout_centerHorizontal="true"
18         android:layout_marginTop="93dp"
19         android:text="@string/hello_world"
20         android:textSize="@dimen/btnTextSize" />
21 
22     <Button
23         android:id="@+id/button1"
24         android:layout_width="wrap_content"
25         android:layout_height="wrap_content"
26         android:layout_alignLeft="@+id/button4"
27         android:layout_alignRight="@+id/textView2"
28         android:layout_below="@+id/textView2"
29         android:layout_marginTop="44dp"
30         android:text="进入普通训练系统"
31         android:textSize="@dimen/btnTextSizes" />
32 
33     <Button
34         android:id="@+id/button4"
35         android:layout_width="wrap_content"
36         android:layout_height="wrap_content"
37         android:layout_alignLeft="@+id/textView2"
38         android:layout_alignRight="@+id/textView2"
39         android:layout_below="@+id/button1"
40         android:text="@string/panduan1"
41         android:textSize="@dimen/btnTextSizes" />
42 
43     <Button
44         android:id="@+id/button2"
45         style="?android:attr/buttonStyleSmall"
46         android:layout_width="wrap_content"
47         android:layout_height="wrap_content"
48         android:layout_alignLeft="@+id/button4"
49         android:layout_alignRight="@+id/button4"
50         android:layout_below="@+id/button4"
51         android:text="进入选择题训练系统"
52         android:textSize="@dimen/btnTextSizes" />
53 
54     <Button
55         android:id="@+id/button3"
56         style="?android:attr/buttonStyleSmall"
57         android:layout_width="wrap_content"
58         android:layout_height="wrap_content"
59         android:layout_alignLeft="@+id/button4"
60         android:layout_alignRight="@+id/button2"
61         android:layout_below="@+id/button2"
62         android:text="进入考试题目系统"
63         android:textSize="@dimen/btnTextSizes" />
64 
65 </RelativeLayout>
activity_main.xml
 1 package com.example.calculator;
 2 
 3 import java.text.ChoiceFormat;
 4 
 5 import android.app.Activity;
 6 import android.content.Intent;
 7 import android.os.Bundle;
 8 import android.view.Menu;
 9 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.widget.Button;
12 import android.widget.RadioButton;
13 import android.widget.RadioGroup;
14 import android.widget.RadioGroup.OnCheckedChangeListener;
15 import android.widget.TextView;
16 
17 public class CalculatorSet extends Activity{
18     private TextView number;
19     private RadioGroup radio;
20     private RadioButton r;
21     private int i=0,g;
22     private Button xunlian;
23     private int []number1=new int[]{0,1,2,3};
24     protected void onCreate(Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         setContentView(R.layout.activtity_calculator_set);
27         number=(TextView)findViewById(R.id.number1);
28         radio=(RadioGroup)findViewById(R.id.group);
29         xunlian=(Button)findViewById(R.id.xunlian);
30         radio.setOnCheckedChangeListener(new OnCheckedChangeListener() {
31             
32             @Override
33             public void onCheckedChanged(RadioGroup arg0, int arg1) {
34                 // TODO Auto-generated method stub
35                 r=(RadioButton)findViewById(arg1);
36             }
37         });
38        xunlian.setOnClickListener(new OnClickListener() {
39         
40         @Override
41         public void onClick(View arg0) {
42             // TODO Auto-generated method stub
43             for (int g=0; g<4;g++){
44                    RadioButton r=(RadioButton)radio.getChildAt(g);
45                     if(r.isChecked()){
46                      i=number1[g];
47                      break;
48                     }
49                     
50                 }
51             g=Integer.valueOf(number.getText().toString());
52             Intent intent=new Intent();
53             Bundle bundle=new Bundle();
54             bundle.putInt("suanfa", i);
55             bundle.putInt("shumu",g);
56             intent.setClass(CalculatorSet.this,CalculatorActivity.class);
57             intent.putExtras(bundle);
58             startActivity(intent);
59         }
60     });    
61     }
62 
63     @Override
64     public boolean onCreateOptionsMenu(Menu menu) {
65         // Inflate the menu; this adds items to the action bar if it is present.
66         getMenuInflater().inflate(R.menu.main, menu);
67         return true;
68     }
69 
70 }
CalculatorSet.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:background="@drawable/lovely1"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/textView1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignParentTop="true"
14         android:layout_centerHorizontal="true"
15         android:layout_marginTop="23dp"
16         android:text="@string/title_activity_set"
17         android:textSize="30sp" />
18 
19        <RadioGroup
20            android:id="@+id/panduangroup"
21            android:layout_width="wrap_content"
22            android:layout_height="wrap_content"
23            android:layout_below="@+id/textView1"
24            android:layout_centerHorizontal="true"
25            android:layout_marginTop="125dp"
26            android:orientation="horizontal" >
27 
28            <RadioButton
29                android:id="@+id/radio0"
30                android:layout_width="wrap_content"
31                android:layout_height="wrap_content"
32                android:text="@string/add" />
33 
34            <RadioButton
35                android:id="@+id/radio2"
36                android:layout_width="wrap_content"
37                android:layout_height="wrap_content"
38                android:layout_alignLeft="@+id/radio0"
39                android:layout_below="@+id/radio0"
40                android:text="@string/jian" />
41 
42            <RadioButton
43                android:id="@+id/radio3"
44                android:layout_width="wrap_content"
45                android:layout_height="wrap_content"
46                android:text="@string/cheng" />
47 
48            <RadioButton
49                android:id="@+id/radio4"
50                android:layout_width="wrap_content"
51                android:layout_height="wrap_content"
52                android:text="@string/chu" />
53        </RadioGroup>
54 
55        <TextView
56            android:id="@+id/textView2"
57            android:layout_width="wrap_content"
58            android:layout_height="wrap_content"
59            android:layout_alignParentLeft="true"
60            android:layout_below="@+id/textView1"
61            android:layout_marginLeft="14dp"
62            android:layout_marginTop="41dp"
63            android:text="@string/the_number_of_calculator"
64            android:textSize="20sp" />
65 
66        <EditText
67            android:id="@+id/panduannumber"
68            android:layout_width="wrap_content"
69            android:layout_height="wrap_content"
70            android:layout_alignBottom="@+id/textView2"
71            android:layout_toRightOf="@+id/textView2"
72            android:ems="10"
73            android:inputType="number" />
74 
75        <Button
76            android:id="@+id/panduanxunlian"
77            android:layout_width="wrap_content"
78            android:layout_height="wrap_content"
79            android:layout_alignParentLeft="true"
80            android:layout_alignRight="@+id/panduannumber"
81            android:layout_below="@+id/panduangroup"
82            android:layout_marginTop="74dp"
83            android:text="训练开始" />
84 
85 </RelativeLayout>
activity_calculator_set.xml
  1 package com.example.calculator;
  2 
  3 import java.util.Random;
  4 
  5 import android.os.Bundle;
  6 import android.app.Activity;
  7 import android.content.Intent;
  8 import android.view.Menu;
  9 import android.view.View;
 10 import android.view.View.OnClickListener;
 11 import android.widget.Button;
 12 import android.widget.EditText;
 13 import android.widget.TextView;
 14 import android.widget.Toast;
 15 
 16 public class CalculatorActivity extends Activity {
 17     private final Random num1=new Random();
 18     private final Random num2=new Random();
 19     private final Random r = new Random();
 20     private Button next;
 21     private char[] ch = {'+','-','*','/'};//字符数组
 22     //private int[]puanduan;
 23     private int index; //随机数,小于数组的长度数, 0~3
 24     private char a;
 25     private TextView text1,text2,text3;
 26     private EditText answer;
 27     private Button surebutton;//确定按钮
 28     private Button caogaozhi;//草稿纸
 29     private int i,m=0;
 30     private String c;
 31     private String e;
 32     private String b;
 33     private int i1,i2,i3;
 34     private int n=0;
 35     @Override
 36     protected void onCreate(Bundle savedInstanceState) {
 37         super.onCreate(savedInstanceState);
 38         setContentView(R.layout.activity_calculator);
 39         Bundle bundle=getIntent().getExtras();
 40         index=bundle.getInt("suanfa");
 41         a=ch[index];
 42         i=bundle.getInt("shumu");
 43         final String[]puanduan=new String[i];
 44         final String[]title1=new String[100];
 45         text1=(TextView)findViewById(R.id.textView1);//随机数字
 46         text2=(TextView)findViewById(R.id.textView2);//运算符号
 47         text3=(TextView)findViewById(R.id.textView3);//随机数字
 48         answer=(EditText)findViewById(R.id.editText1);//运算结果
 49         next=(Button)findViewById(R.id.next);
 50         caogaozhi=(Button)findViewById(R.id.caogaozhi);
 51         String c=String.valueOf(num1.nextInt(100));
 52         i2=Integer.valueOf(c);
 53         String d=String.valueOf(a);
 54         String e=String.valueOf(num2.nextInt(100));
 55         i3=Integer.valueOf(e);
 56         text1.setText(c);//随机数1-100
 57         text2.setText(d);//随机运算符+,-,*,/
 58         text3.setText(e);//随机数1-100
 59         title1[n]=c+d+e;
 60         n++;
 61         surebutton=(Button)findViewById(R.id.surebutton);//确定按钮
 62         surebutton.setOnClickListener(new OnClickListener() {
 63             @Override
 64             public void onClick(View arg0) {
 65                 // TODO Auto-generated method stub
 66                 final String b=answer.getText().toString();//获取输入的数值
 67                 i1=Integer.valueOf(b);
 68                 switch(index){
 69                 case 0:
 70                 {
 71                     if(i1==(i2+i3))
 72                     {
 73                         Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
 74                         puanduan[m]="正确";
 75                     }
 76                     else
 77                     {
 78                         Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
 79                         puanduan[m]="错误";
 80                     }
 81                     break;
 82                 }
 83                 case 1:
 84                 {
 85                     if(i1==(i2-i3))
 86                     {
 87                         Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
 88                         puanduan[m]="正确";
 89                     }
 90                     else
 91                     {
 92                         Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
 93                         puanduan[m]="错误";
 94                     }
 95                     break;
 96                 }
 97                 case 2:{
 98                     if(i1==(i2*i3))
 99                     {
100                         Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
101                         puanduan[m]="正确";
102                     }
103                     else
104                     {
105                         Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
106                         puanduan[m]="错误";
107                     }
108                     break;        
109                 }
110                 case 3:
111                 {
112                     if(i3!=0){
113                     if(i1==(i2/i3))
114                     {
115                         Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
116                         puanduan[m]="正确";
117                     }
118                     else
119                     {
120                         Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
121                         puanduan[m]="错误";
122                     }
123                     }
124                     break;
125                 }
126                 }
127                 i--;
128                 m++;
129                 if(i==0){
130                     Toast.makeText(CalculatorActivity.this,"已经到了了题目个数!",Toast.LENGTH_LONG ).show();
131                     
132                 }
133                 else{
134                     String c=String.valueOf(num1.nextInt(100));
135                     i2=Integer.valueOf(c);
136                     String d=String.valueOf(a);
137                     String e=String.valueOf(num2.nextInt(100));
138                     i3=Integer.valueOf(e);
139                     text1.setText(c);//随机数1-100
140                     text2.setText(d);//随机运算符+,-,*,/
141                     text3.setText(e);//随机数1-100    
142                     title1[n]=c+d+e;
143                     n++;
144                     answer.setText(null);
145                 }
146             }
147         });
148         next.setOnClickListener(new OnClickListener() {
149             
150             @Override
151             public void onClick(View arg0) {
152                 if(i==0){
153                 Intent intent=new Intent();
154                 Bundle bundle2=new Bundle();
155                 bundle2.putStringArray("panduan", puanduan);
156                 bundle2.putStringArray("titlearry", title1);
157                 bundle2.putInt("number", m);
158                 intent.putExtras(bundle2);
159                 intent.setClass(CalculatorActivity.this,resultActivity.class);
160                 startActivity(intent);
161                 CalculatorActivity.this.finish();
162                 }
163                 else
164                     Toast.makeText(CalculatorActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show();
165             }
166         });
167         caogaozhi.setOnClickListener(new OnClickListener() {
168             
169             @Override
170             public void onClick(View arg0) {
171                 // TODO Auto-generated method stub
172                 Intent intent=new Intent();
173                 intent.setClass(CalculatorActivity.this, HuabuActivity.class);
174                 startActivity(intent);
175                 CalculatorActivity.this.finish();
176             }
177         });
178     }
179 
180     @Override
181     public boolean onCreateOptionsMenu(Menu menu) {
182         // Inflate the menu; this adds items to the action bar if it is present.
183         getMenuInflater().inflate(R.menu.calculator, menu);
184         return true;
185     }
186 
187 }
CalculatorActivity.java
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:background="@drawable/lovely3"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context=".CalculatorActivity" >
11 
12     <TextView
13         android:id="@+id/textView1"
14         android:layout_width="50dp"
15         android:layout_height="wrap_content"
16         android:layout_marginTop="100dp" />
17 
18     <TextView
19         android:id="@+id/textView2"
20         android:layout_width="30dp"
21         android:layout_height="wrap_content"
22         android:layout_alignBaseline="@+id/textView1"
23         android:layout_alignBottom="@+id/textView1"
24         android:layout_toRightOf="@+id/textView1" />
25 
26     <TextView
27         android:id="@+id/textView3"
28         android:layout_width="50dp"
29         android:layout_height="wrap_content"
30         android:layout_alignBaseline="@+id/textView2"
31         android:layout_alignBottom="@+id/textView2"
32         android:layout_toRightOf="@+id/textView2" />
33 
34     <TextView
35         android:id="@+id/textView4"
36         android:layout_width="wrap_content"
37         android:layout_height="wrap_content"
38         android:layout_alignBaseline="@+id/textView3"
39         android:layout_alignBottom="@+id/textView3"
40         android:layout_toRightOf="@+id/textView3"
41         android:text="=" />
42 
43     <EditText
44         android:id="@+id/editText1"
45         android:layout_width="wrap_content"
46         android:layout_height="wrap_content"
47         android:layout_alignBaseline="@+id/textView4"
48         android:layout_alignBottom="@+id/textView4"
49         android:layout_marginLeft="38dp"
50         android:layout_toRightOf="@+id/textView4"
51         android:ems="10"
52         android:inputType="number" >
53 
54         <requestFocus />
55     </EditText>
56 
57     <Button
58         android:id="@+id/surebutton"
59         android:layout_width="wrap_content"
60         android:layout_height="wrap_content"
61         android:layout_alignLeft="@+id/textView1"
62         android:layout_alignParentRight="true"
63         android:layout_below="@+id/editText1"
64         android:layout_marginTop="88dp"
65         android:text="确定" />
66 
67     <Button
68         android:id="@+id/caogaozhi"
69         android:layout_width="wrap_content"
70         android:layout_height="wrap_content"
71         android:layout_alignLeft="@+id/next"
72         android:layout_alignRight="@+id/surebutton"
73         android:layout_below="@+id/surebutton"
74         android:text="草稿纸" />
75 
76     <Button
77         android:id="@+id/next"
78         android:layout_width="wrap_content"
79         android:layout_height="wrap_content"
80         android:layout_alignLeft="@+id/surebutton"
81         android:layout_alignRight="@+id/surebutton"
82         android:layout_below="@+id/caogaozhi"
83         android:text="打印分数" />
84 
85 </RelativeLayout>
activity_calculator.xml
 1 package com.example.calculator;
 2 
 3 import android.app.Activity;
 4 import android.content.Intent;
 5 import android.os.Bundle;
 6 import android.view.Menu;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.widget.Button;
10 import android.widget.RadioGroup;
11 import android.widget.TextView;
12 import android.widget.RadioGroup.OnCheckedChangeListener;
13 
14 public class resultActivity extends Activity {
15     private TextView number;
16     private TextView panduan;
17     //private TextView sum;
18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         setContentView(R.layout.activity_result);
21         Bundle bundle=getIntent().getExtras();
22         number=(TextView)findViewById(R.id.thenumber);
23         panduan=(TextView)findViewById(R.id.pan);
24          int i=bundle.getInt("number");
25          String []puanduan=bundle.getStringArray("panduan");
26          String []title1=bundle.getStringArray("titlearry");
27          String aa="";
28          String aaa="";
29         for(int g=0;g<i;g++){
30             aa+=title1[g]+"\n";
31             aaa+=puanduan[g]+"\n";
32             number.setText(aa);
33             panduan.setText(aaa);;
34         }
35         }
36 
37     @Override
38     public boolean onCreateOptionsMenu(Menu menu) {
39         // Inflate the menu; this adds items to the action bar if it is present.
40         getMenuInflater().inflate(R.menu.main, menu);
41         return true;
42     }
43 
44 }
resultActivity.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:background="@drawable/lovely2"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/textView1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignParentTop="true"
14         android:layout_centerHorizontal="true"
15         android:layout_marginTop="14dp"
16         android:text="@string/result" 
17         android:textSize="30sp"/>
18 
19     <TextView
20         android:id="@+id/textView3"
21         android:layout_width="wrap_content"
22         android:layout_height="wrap_content"
23         android:layout_alignBottom="@+id/textView2"
24         android:layout_toRightOf="@+id/textView1"
25         android:text="@string/panduan"
26         android:textSize="20sp" />
27 
28     <TextView
29         android:id="@+id/textView2"
30         android:layout_width="wrap_content"
31         android:layout_height="wrap_content"
32         android:layout_below="@+id/textView1"
33         android:layout_marginTop="14dp"
34         android:layout_toLeftOf="@+id/textView1"
35         android:text="@string/number"
36         android:textSize="20sp" />
37 
38     <TextView
39         android:id="@+id/thenumber"
40         android:layout_width="wrap_content"
41         android:layout_height="wrap_content"
42         android:layout_alignLeft="@+id/textView2"
43         android:layout_below="@+id/textView2"
44         android:layout_marginTop="20dp"
45         android:text="TextView" />
46 
47     <TextView
48         android:id="@+id/pan"
49         android:layout_width="wrap_content"
50         android:layout_height="wrap_content"
51         android:layout_alignBaseline="@+id/thenumber"
52         android:layout_alignBottom="@+id/thenumber"
53         android:layout_toRightOf="@+id/textView1"
54         android:text="TextView" />
55 
56 </RelativeLayout>
activity_result.xml
 1 package com.example.calculator;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.content.Intent;
 6 import android.view.Menu;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.widget.Button;
10 import android.widget.RadioButton;
11 import android.widget.RadioGroup;
12 import android.widget.TextView;
13 import android.widget.RadioGroup.OnCheckedChangeListener;
14  
15 public class ChoiceSet extends Activity {
16     private TextView number;
17     private int i=0,g;
18     private Button xunlian;
19  
20     @Override
21     protected void onCreate(Bundle savedInstanceState) {
22         super.onCreate(savedInstanceState);
23         setContentView(R.layout.activity_choice_set);
24         number=(TextView)findViewById(R.id.number1);
25         xunlian=(Button)findViewById(R.id.xunlian);
26         
27         xunlian.setOnClickListener(new OnClickListener() {
28              
29             @Override
30             public void onClick(View arg0) {
31                 // TODO Auto-generated method stub
32                 
33              g=Integer.valueOf(number.getText().toString());
34                 Intent intent=new Intent();
35                 Bundle bundle=new Bundle();
36                 bundle.putInt("shumu",g);
37                 intent.setClass(ChoiceSet.this,ChoiceActivity.class);
38                 intent.putExtras(bundle);
39                 startActivity(intent);
40             }
41         });
42     }
43  
44     @Override
45     public boolean onCreateOptionsMenu(Menu menu) {
46         // Inflate the menu; this adds items to the action bar if it is present.
47         getMenuInflater().inflate(R.menu.choice_set, menu);
48         return true;
49     }
50  
51 }
ChoiceSet.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:background="@drawable/lovely1"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/textView1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignParentTop="true"
14         android:layout_centerHorizontal="true"
15         android:layout_marginTop="23dp"
16         android:text="@string/title_activity_set"
17         android:textSize="30sp" />
18 
19        <TextView
20            android:id="@+id/textView2"
21            android:layout_width="wrap_content"
22            android:layout_height="wrap_content"
23            android:layout_alignParentLeft="true"
24            android:layout_below="@+id/textView1"
25            android:layout_marginLeft="14dp"
26            android:layout_marginTop="41dp"
27            android:text="@string/the_number_of_calculator"
28            android:textSize="20sp" />
29 
30        <EditText
31            android:id="@+id/panduannumber"
32            android:layout_width="wrap_content"
33            android:layout_height="wrap_content"
34            android:layout_alignBottom="@+id/textView2"
35            android:layout_toRightOf="@+id/textView2"
36            android:ems="10"
37            android:inputType="number" />
38 
39        <Button
40            android:id="@+id/panduanxunlian"
41            android:layout_width="wrap_content"
42            android:layout_height="wrap_content"
43            android:layout_alignParentLeft="true"
44            android:layout_alignRight="@+id/panduannumber"
45            android:layout_below="@+id/panduangroup"
46            android:layout_marginTop="74dp"
47            android:text="训练开始" />
48 
49 </RelativeLayout>
activity_choice_set.xml
  1 package com.example.calculator;
  2 
  3 import java.util.Random;
  4 
  5 import android.os.Bundle;
  6 import android.app.Activity;
  7 import android.view.Menu;
  8 
  9 import android.os.Bundle;
 10 import android.app.ActionBar;
 11 import android.app.Activity;
 12 import android.content.Intent;
 13 import android.view.Menu;
 14 import android.view.MenuItem;
 15 import android.view.View;
 16 import android.view.View.OnClickListener;
 17 import android.widget.Button;
 18 import android.widget.CheckBox;
 19 import android.widget.TextView;
 20 import android.widget.Toast;
 21 
 22 public class ChoiceActivity extends Activity {
 23 
 24     private TextView text1,text2,text3;
 25     private CheckBox checkbox1,checkbox2,checkbox3,checkbox4;
 26     private Button btn1,btn2,caogaozhi;
 27     private int i,m=0;
 28     private int n=0;
 29     private final Random num1=new Random();
 30     private final Random num2=new Random();
 31     private final Random num3=new Random();
 32     private final Random num4=new Random();
 33     private final Random num5=new Random();
 34     private final Random r = new Random();
 35     private int x1;
 36     private int x2;
 37     private int x3;
 38     
 39     private char[] ch={'+','-','*','/'}; //字符数组
 40     private int index = r.nextInt(ch.length); //随机数,小于数组的长度数, 0~3
 41     private char x;
 42     private char d;
 43 
 44     @Override
 45     protected void onCreate(Bundle savedInstanceState) {
 46         ActionBar actionBar=getActionBar();
 47         actionBar.setDisplayShowHomeEnabled(true);
 48         actionBar.setDisplayHomeAsUpEnabled(true);
 49         super.onCreate(savedInstanceState);
 50         setContentView(R.layout.activity_choice);
 51         Bundle bundle=getIntent().getExtras();
 52         index=bundle.getInt("suanfa");
 53         d=ch[index];
 54         i=bundle.getInt("shumu");
 55         final String[]puanduan=new String[i];
 56         final String[]title1=new String[100];
 57         
 58         text1=(TextView)findViewById(R.id.textView1);
 59         text2=(TextView)findViewById(R.id.textView2);
 60         text3=(TextView)findViewById(R.id.textView3);
 61         
 62         checkbox1=(CheckBox)findViewById(R.id.checkBox1);
 63         checkbox2=(CheckBox)findViewById(R.id.checkBox2);
 64         checkbox3=(CheckBox)findViewById(R.id.checkBox3);
 65         checkbox4=(CheckBox)findViewById(R.id.checkBox4);
 66         btn1=(Button)findViewById(R.id.button1);
 67         btn2=(Button)findViewById(R.id.button2);
 68         caogaozhi=(Button)findViewById(R.id.caogaozhi3);
 69         
 70         final String a=String.valueOf(num1.nextInt(100));
 71         x1=Integer.valueOf(a);
 72         final String b=String.valueOf(num2.nextInt(100));
 73         x2=Integer.valueOf(b);
 74         final String c=String.valueOf(num3.nextInt(100));
 75         final String f=String.valueOf(num4.nextInt(100));
 76         final String z=String.valueOf(num5.nextInt(100));
 77         final String e=String.valueOf(d);
 78         
 79         text1.setText(a);
 80         text3.setText(b);
 81         text2.setText(e);
 82     
 83         
 84         checkbox1.setText(f);
 85         checkbox2.setText(z);
 86         checkbox4.setText(c);
 87         
 88         if(index==0){
 89             x3=x1+x2;
 90             final String h=String.valueOf(x3);
 91             checkbox3.setText(h);
 92         }
 93         if(index==1){
 94             x3=x1-x2;
 95             final String h=String.valueOf(x3);
 96             checkbox3.setText(h);
 97         }
 98         if(index==2){
 99             x3=x1*x2;
100             final String h=String.valueOf(x3);
101             checkbox3.setText(h);
102         }
103         if(index==3){
104             x3=x1/x2;
105             final String h=String.valueOf(x3);
106             checkbox3.setText(h);
107         }
108         
109         //"确定"按钮
110         btn1.setOnClickListener(new OnClickListener() {
111             
112             final String h=String.valueOf(x3);
113             
114             @Override
115             public void onClick(View arg0) {
116                 // TODO Auto-generated method stub
117                 
118                 if(checkbox3.isChecked()){
119                     Toast.makeText(ChoiceActivity.this, "正确", Toast.LENGTH_SHORT).show();
120                     puanduan[m]="正确";
121                 }
122                 if(!(checkbox3.isChecked())){
123                     Toast.makeText(ChoiceActivity.this, "错误"+h, Toast.LENGTH_SHORT).show();
124                     puanduan[m]="错误";
125                 }
126                 i--;
127                 m++;
128                 if(i==0){
129                     Toast.makeText(ChoiceActivity.this,"已经到了了题目个数!",Toast.LENGTH_LONG ).show();
130                     
131                 }
132                 else{
133                     final String a=String.valueOf(num1.nextInt(100));
134                     x1=Integer.valueOf(a);
135                     final String b=String.valueOf(num2.nextInt(100));
136                     x2=Integer.valueOf(b);
137                     final String c=String.valueOf(num3.nextInt(100));
138                     final String f=String.valueOf(num4.nextInt(100));
139                     final String z=String.valueOf(num5.nextInt(100));
140                     final String e=String.valueOf(d);
141                     
142                     title1[n]=c+d+e;
143                     n++;
144                     
145                     text1.setText(a);
146                     text3.setText(b);
147                     text2.setText(e);
148                     
149                     checkbox1.setText(f);
150                     checkbox2.setText(z);
151                     checkbox4.setText(c);
152                     
153                     if(index==0){
154                         x3=x1+x2;
155                         final String h=String.valueOf(x3);
156                         checkbox3.setText(h);
157                     }
158                     if(index==1){
159                         x3=x1-x2;
160                         final String h=String.valueOf(x3);
161                         checkbox3.setText(h);
162                     }
163                     if(index==2){
164                         x3=x1*x2;
165                         final String h=String.valueOf(x3);
166                         checkbox3.setText(h);
167                     }
168                     if(index==3){
169                         x3=x1/x2;
170                         final String h=String.valueOf(x3);
171                         checkbox3.setText(h);
172                     }
173                 }
174                 
175             }
176         });
177         
178         btn2.setOnClickListener(new OnClickListener() {
179             
180             @Override
181             public void onClick(View arg0) {
182                 if(i==0){
183                 Intent intent=new Intent();
184                 Bundle bundle2=new Bundle();
185                 bundle2.putStringArray("panduan", puanduan);
186                 bundle2.putStringArray("titlearry", title1);
187                 bundle2.putInt("number", m);
188                 intent.putExtras(bundle2);
189                 intent.setClass(ChoiceActivity.this,ChoiceResult.class);
190                 startActivity(intent);
191                 ChoiceActivity.this.finish();
192                 }
193                 else
194                     Toast.makeText(ChoiceActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show();
195             }
196         });
197         
198         caogaozhi.setOnClickListener(new OnClickListener() {
199             
200             @Override
201             public void onClick(View arg0) {
202                 // TODO Auto-generated method stub
203                 Intent intent=new Intent();
204                 intent.setClass(ChoiceActivity.this, HuabuActivity.class);
205                 startActivity(intent);
206                 ChoiceActivity.this.finish();
207             }
208         });
209         
210         
211     }
212 
213     @Override
214     public boolean onCreateOptionsMenu(Menu menu) {
215         // Inflate the menu; this adds items to the action bar if it is present.
216         getMenuInflater().inflate(R.menu.choice, menu);
217         return true;
218     }
219     
220     @Override
221     public boolean onOptionsItemSelected(MenuItem item) {
222         // TODO Auto-generated method stub
223         switch (item.getItemId()) {
224         case android.R.id.home:
225             //创建启动MainActivity的Intent
226             Intent intent=new Intent(this,MainActivity.class);
227             //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出
228             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
229             startActivity(intent);
230             break;
231 
232         default:
233             break;
234         }
235         return super.onOptionsItemSelected(item);
236     }
237 
238 }
ChoiceActivity.java
  1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2     xmlns:tools="http://schemas.android.com/tools"
  3     android:layout_width="match_parent"
  4     android:layout_height="match_parent"
  5     android:background="@drawable/lovely3"
  6     android:paddingBottom="@dimen/activity_vertical_margin"
  7     android:paddingLeft="@dimen/activity_horizontal_margin"
  8     android:paddingRight="@dimen/activity_horizontal_margin"
  9     android:paddingTop="@dimen/activity_vertical_margin"
 10     tools:context=".ChoiceActivity" >
 11  
 12     <TextView
 13         android:id="@+id/textView1"
 14         android:layout_width="50dp"
 15         android:layout_height="wrap_content"
 16         android:layout_marginTop="100dp" />
 17  
 18     <TextView
 19         android:id="@+id/textView2"
 20         android:layout_width="30dp"
 21         android:layout_height="wrap_content"
 22         android:layout_alignBaseline="@+id/textView1"
 23         android:layout_alignBottom="@+id/textView1"
 24         android:layout_toRightOf="@+id/textView1" />
 25  
 26     <TextView
 27         android:id="@+id/textView3"
 28         android:layout_width="50dp"
 29         android:layout_height="wrap_content"
 30         android:layout_alignBaseline="@+id/textView2"
 31         android:layout_alignBottom="@+id/textView2"
 32         android:layout_toRightOf="@+id/textView2" />
 33  
 34     <TextView
 35         android:id="@+id/textView4"
 36         android:layout_width="wrap_content"
 37         android:layout_height="wrap_content"
 38         android:layout_alignBaseline="@+id/textView3"
 39         android:layout_alignBottom="@+id/textView3"
 40         android:layout_toRightOf="@+id/textView3"
 41         android:text="=" />
 42  
 43     <TextView
 44         android:id="@+id/textView5"
 45         android:layout_width="wrap_content"
 46         android:layout_height="wrap_content"
 47         android:layout_alignBaseline="@+id/checkBox1"
 48         android:layout_alignBottom="@+id/checkBox1"
 49         android:layout_toLeftOf="@+id/checkBox1"
 50         android:text="A" />
 51  
 52     <TextView
 53         android:id="@+id/textView6"
 54         android:layout_width="wrap_content"
 55         android:layout_height="wrap_content"
 56         android:layout_alignBaseline="@+id/checkBox2"
 57         android:layout_alignBottom="@+id/checkBox2"
 58         android:layout_alignRight="@+id/textView5"
 59         android:text="B" />
 60  
 61     <TextView
 62         android:id="@+id/textView7"
 63         android:layout_width="wrap_content"
 64         android:layout_height="wrap_content"
 65         android:layout_alignBaseline="@+id/checkBox3"
 66         android:layout_alignBottom="@+id/checkBox3"
 67         android:layout_toLeftOf="@+id/checkBox3"
 68         android:text="C" />
 69  
 70     <TextView
 71         android:id="@+id/textView8"
 72         android:layout_width="wrap_content"
 73         android:layout_height="wrap_content"
 74         android:layout_alignBaseline="@+id/checkBox4"
 75         android:layout_alignBottom="@+id/checkBox4"
 76         android:layout_toLeftOf="@+id/checkBox4"
 77         android:text="D" />
 78  
 79     <CheckBox
 80         android:id="@+id/checkBox4"
 81         android:layout_width="wrap_content"
 82         android:layout_height="wrap_content"
 83         android:layout_alignLeft="@+id/checkBox3"
 84         android:layout_below="@+id/checkBox3" />
 85  
 86     <CheckBox
 87         android:id="@+id/checkBox1"
 88         android:layout_width="wrap_content"
 89         android:layout_height="wrap_content"
 90         android:layout_alignRight="@+id/textView4"
 91         android:layout_centerVertical="true" />
 92  
 93     <CheckBox
 94         android:id="@+id/checkBox2"
 95         android:layout_width="wrap_content"
 96         android:layout_height="wrap_content"
 97         android:layout_alignLeft="@+id/checkBox1"
 98         android:layout_below="@+id/checkBox1" />
 99  
100     <CheckBox
101         android:id="@+id/checkBox3"
102         android:layout_width="wrap_content"
103         android:layout_height="wrap_content"
104         android:layout_alignLeft="@+id/checkBox2"
105         android:layout_below="@+id/checkBox2" />
106 
107     <Button
108         android:id="@+id/caogaozhi3"
109         android:layout_width="wrap_content"
110         android:layout_height="wrap_content"
111         android:layout_alignBaseline="@+id/button2"
112         android:layout_alignBottom="@+id/button2"
113         android:layout_alignParentRight="true"
114         android:text="草稿纸" />
115 
116     <Button
117         android:id="@+id/button1"
118         android:layout_width="wrap_content"
119         android:layout_height="wrap_content"
120         android:layout_alignLeft="@+id/textView1"
121         android:layout_below="@+id/checkBox4"
122         android:layout_marginTop="26dp"
123         android:text="确定" />
124 
125     <Button
126         android:id="@+id/button2"
127         android:layout_width="wrap_content"
128         android:layout_height="wrap_content"
129         android:layout_alignBaseline="@+id/button1"
130         android:layout_alignBottom="@+id/button1"
131         android:layout_toRightOf="@+id/textView8"
132         android:text="打印" />
133  
134 </RelativeLayout>
activity_choice.xml
 1 package com.example.calculator;
 2 
 3 import android.app.Activity;
 4 import android.content.Intent;
 5 import android.os.Bundle;
 6 import android.view.Menu;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.widget.Button;
10 import android.widget.TextView;
11 
12 public class ChoiceResult extends Activity{
13     private TextView t1;
14     private TextView t2;
15     protected void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.activity_choice_result);
18         t1=(TextView)findViewById(R.id.panduan12);
19         t2=(TextView)findViewById(R.id.panduan13);
20         Bundle bundle=getIntent().getExtras();
21         int i=bundle.getInt("panduannumber");
22         String []answer=bundle.getStringArray("panduanarry");
23         String []title1=bundle.getStringArray("titlearry");
24          String aa="";
25          String aaa="";
26         for(int g=0;g<i;g++){
27             aa+=title1[g]+"\n";
28             aaa+=answer[g]+"\n";
29             t1.setText(aa);
30             t2.setText(aaa);;
31         }
32     }
33 
34     @Override
35     public boolean onCreateOptionsMenu(Menu menu) {
36         // Inflate the menu; this adds items to the action bar if it is present.
37         getMenuInflater().inflate(R.menu.main, menu);
38         return true;
39     }
40 
41 }
ChoiceResult.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:background="@drawable/lovely2"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/textView1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignParentTop="true"
14         android:layout_centerHorizontal="true"
15         android:layout_marginTop="14dp"
16         android:text="@string/result" 
17         android:textSize="30sp"/>
18 
19     <TextView
20         android:id="@+id/textView3"
21         android:layout_width="wrap_content"
22         android:layout_height="wrap_content"
23         android:layout_alignBottom="@+id/textView2"
24         android:layout_toRightOf="@+id/textView1"
25         android:text="@string/panduan"
26         android:textSize="20sp" />
27 
28     <TextView
29         android:id="@+id/textView2"
30         android:layout_width="wrap_content"
31         android:layout_height="wrap_content"
32         android:layout_below="@+id/textView1"
33         android:layout_marginTop="14dp"
34         android:layout_toLeftOf="@+id/textView1"
35         android:text="@string/number"
36         android:textSize="20sp" />
37 
38     <TextView
39         android:id="@+id/thenumber"
40         android:layout_width="wrap_content"
41         android:layout_height="wrap_content"
42         android:layout_alignLeft="@+id/textView2"
43         android:layout_below="@+id/textView2"
44         android:layout_marginTop="20dp"
45         android:text="TextView" />
46 
47     <TextView
48         android:id="@+id/pan"
49         android:layout_width="wrap_content"
50         android:layout_height="wrap_content"
51         android:layout_alignBaseline="@+id/thenumber"
52         android:layout_alignBottom="@+id/thenumber"
53         android:layout_toRightOf="@+id/textView1"
54         android:text="TextView" />
55 
56 </RelativeLayout>
activity_choice_result.xml
  1 package com.example.calculator;
  2 
  3 import java.util.Random;
  4 
  5 import android.app.Activity;
  6 import android.content.Intent;
  7 import android.os.Bundle;
  8 import android.view.Menu;
  9 import android.view.View;
 10 import android.view.View.OnClickListener;
 11 import android.widget.Button;
 12 import android.widget.RadioButton;
 13 import android.widget.RadioGroup;
 14 import android.widget.Toast;
 15 import android.widget.RadioGroup.OnCheckedChangeListener;
 16 import android.widget.TextView;
 17 
 18 public class panduanActivity extends Activity{
 19     private Button next1;
 20     private Button result1;
 21     private Button caogaozhi;
 22     private RadioGroup panduan;
 23     private int []number12=new int[]{0,1};
 24     private RadioButton m;
 25     private TextView timu1;
 26     private int index,i;
 27     private int k,j,l,sum,wrong,right,sign=0,label=0,n=0;
 28     private char a;
 29     private final Random num1=new Random();
 30     private final Random num2=new Random();
 31     private final Random r = new Random();
 32     private char[] ch = {'+','-','*','/'};
 33     protected void onCreate(Bundle savedInstanceState) {
 34         super.onCreate(savedInstanceState);
 35         setContentView(R.layout.activity_panduan);
 36         panduan=(RadioGroup)findViewById(R.id.group2);
 37         next1=(Button)findViewById(R.id.next1);
 38         result1=(Button)findViewById(R.id.result1);
 39         timu1=(TextView)findViewById(R.id.timu1);
 40         caogaozhi=(Button)findViewById(R.id.caogaozhi2);
 41         Bundle bundle=getIntent().getExtras();
 42         index=bundle.getInt("panduansuanfa");
 43         a=ch[index];
 44         i=bundle.getInt("panduanshumu");
 45         final String[] title1=new String[100];
 46         final String []answer=new String[i];
 47         String c=String.valueOf(num1.nextInt(100));
 48         String b=String.valueOf(num2.nextInt(100));
 49         String g=String.valueOf(r.nextInt(3));
 50         k=Integer.valueOf(g);
 51         l=Integer.valueOf(c);
 52         j=Integer.valueOf(b);
 53         String d=String.valueOf(a);    
 54         switch(index){
 55         case 0:
 56             sum=l+j;
 57             break;
 58         case 1:
 59             sum=l-j;
 60             break;
 61         case 2:
 62             sum=l*j;
 63             break;
 64         case 4:
 65             sum=l/j;
 66             break;
 67         }
 68         switch(k){
 69         case 0:
 70             timu1.setText(c+d+b+"="+String.valueOf(sum));
 71             title1[n]=c+d+b+"="+String.valueOf(sum);
 72             n++;
 73             right=0;
 74             break;
 75         case 1:
 76             timu1.setText(c+d+b+"="+String.valueOf(sum+1));
 77             title1[n]=c+d+b+"="+String.valueOf(sum+1);
 78             n++;
 79             right=1;
 80             break;
 81         case 2:
 82             timu1.setText(c+d+b+"="+String.valueOf(sum+2));
 83             title1[n]=c+d+b+"="+String.valueOf(sum+2);
 84             n++;
 85             right=1;
 86             break;
 87             default:
 88                 break;
 89         }
 90         panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() {
 91             
 92             @Override
 93             public void onCheckedChanged(RadioGroup arg0, int arg1) {
 94                 // TODO Auto-generated method stub
 95                 m=(RadioButton)findViewById(arg1);
 96             }
 97         });
 98         next1.setOnClickListener(new OnClickListener() {
 99             
100             @Override
101             public void onClick(View arg0) {
102                 for (int g=0; g<2;g++){
103                        RadioButton m=(RadioButton)panduan.getChildAt(g);
104                         if(m.isChecked()){
105                          sign=number12[g];
106                          break;
107                         }
108                 }
109                 if(i!=0){
110             if(sign==right){
111                 Toast.makeText(panduanActivity.this, "选择正确", Toast.LENGTH_LONG).show();
112                 answer[label]="right";
113             }
114             if(sign!=right){
115                 Toast.makeText(panduanActivity.this, "选择错误", Toast.LENGTH_LONG).show();
116                 answer[label]="wrong";
117             }
118             i--;
119             label++;
120             String c=String.valueOf(num1.nextInt(100));
121             String b=String.valueOf(num2.nextInt(100));
122             String g=String.valueOf(r.nextInt(3));
123             k=Integer.valueOf(g);
124             l=Integer.valueOf(c);
125             j=Integer.valueOf(b);
126             String d=String.valueOf(a);    
127             switch(index){
128             case 0:
129                 sum=l+j;
130                 break;
131             case 1:
132                 sum=l-j;
133                 break;
134             case 2:
135                 sum=l*j;
136                 break;
137             case 4:
138                 sum=l/j;
139                 break;
140             }
141             switch(k){
142             case 0:
143                 timu1.setText(c+d+b+"="+String.valueOf(sum));
144                 title1[n]=c+d+b+"="+String.valueOf(sum);
145                 n++;
146                 right=0;
147                 break;
148             case 1:
149                 timu1.setText(c+d+b+"="+String.valueOf(sum+1));
150                 title1[n]=c+d+b+"="+String.valueOf(sum+1);
151                 n++;
152                 right=1;
153                 break;
154             case 2:
155                 timu1.setText(c+d+b+"="+String.valueOf(sum+2));
156                 title1[n]=c+d+b+"="+String.valueOf(sum+2);
157                 n++;
158                 right=1;
159                 break;
160                 default:
161                     break;
162             }
163             panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() {
164                 
165                 @Override
166                 public void onCheckedChanged(RadioGroup arg0, int arg1) {
167                     // TODO Auto-generated method stub
168                     m=(RadioButton)findViewById(arg1);
169                 }
170             });
171                 }
172                 else
173                 {
174                 Toast.makeText(panduanActivity.this,"题目已做完", Toast.LENGTH_LONG).show();
175                 timu1.setText(null);
176                 }
177             }
178         });
179         result1.setOnClickListener(new OnClickListener() {
180             
181             @Override
182             public void onClick(View arg0) {
183             if(i!=0)
184                 Toast.makeText(panduanActivity.this, "题目没有做完,请继续完成", Toast.LENGTH_LONG).show();
185             else{
186                 Intent intent=new Intent();
187                 Bundle bundle2=new Bundle();
188                 intent.setClass(panduanActivity.this,panduanresult.class);
189                 bundle2.putInt("panduannumber", label);
190                 bundle2.putStringArray("panduanarry", answer);
191                 bundle2.putStringArray("titlearry", title1);
192                 intent.putExtras(bundle2);
193                 startActivity(intent);
194             }
195                 
196             }
197         });
198         caogaozhi.setOnClickListener(new OnClickListener() {
199             
200             @Override
201             public void onClick(View arg0) {
202                 // TODO Auto-generated method stub
203                 Intent intent=new Intent();
204                 intent.setClass(panduanActivity.this, HuabuActivity.class);
205                 startActivity(intent);
206                 panduanActivity.this.finish();
207             }
208         });
209     }
210 
211     @Override
212     public boolean onCreateOptionsMenu(Menu menu) {
213         // Inflate the menu; this adds items to the action bar if it is present.
214         getMenuInflater().inflate(R.menu.main, menu);
215         return true;
216     }
217 
218 
219 }
panduanActivity.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:background="@drawable/lovely3"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/timu1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignBaseline="@+id/textView1"
14         android:layout_alignBottom="@+id/textView1"
15         android:layout_marginLeft="17dp"
16         android:layout_toRightOf="@+id/textView1"
17         android:text="TextView" 
18         android:textSize="20sp"/>
19 
20       <TextView
21           android:id="@+id/textView1"
22           android:layout_width="wrap_content"
23           android:layout_height="wrap_content"
24           android:layout_alignParentLeft="true"
25           android:layout_alignParentTop="true"
26           android:layout_marginTop="60dp"
27           android:text="题目:"
28           android:textSize="20sp" />
29 
30       <RadioGroup
31           android:id="@+id/group2"
32           android:layout_width="wrap_content"
33           android:layout_height="wrap_content"
34           android:layout_alignParentLeft="true"
35           android:layout_below="@+id/timu1"
36           android:layout_marginTop="38dp"
37           android:orientation="vertical" >
38 
39           <RadioButton
40               android:id="@+id/radio0"
41               android:layout_width="wrap_content"
42               android:layout_height="wrap_content"
43               android:checked="true"
44               android:text="@string/right"
45               android:textSize="20sp" />
46 
47           <RadioButton
48               android:id="@+id/radio1"
49               android:layout_width="wrap_content"
50               android:layout_height="wrap_content"
51               android:layout_alignLeft="@+id/radio0"
52               android:layout_below="@+id/radio0"
53               android:text="@string/wrong"
54               android:textSize="20sp" />
55       </RadioGroup>
56 
57       <Button
58           android:id="@+id/caogaozhi2"
59           android:layout_width="wrap_content"
60           android:layout_height="wrap_content"
61           android:layout_above="@+id/result1"
62           android:layout_alignParentLeft="true"
63           android:layout_alignParentRight="true"
64           android:text="草稿纸" />
65 
66       <Button
67           android:id="@+id/next1"
68           android:layout_width="wrap_content"
69           android:layout_height="wrap_content"
70           android:layout_alignParentBottom="true"
71           android:layout_alignParentLeft="true"
72           android:layout_alignParentRight="true"
73           android:layout_marginBottom="51dp"
74           android:text="下一题" />
75 
76       <Button
77           android:id="@+id/result1"
78           android:layout_width="wrap_content"
79           android:layout_height="wrap_content"
80           android:layout_above="@+id/next1"
81           android:layout_alignParentLeft="true"
82           android:layout_alignParentRight="true"
83           android:text="结果输出" />
84 
85 </RelativeLayout>
activity_panduan.xml
 1 package com.example.calculator;
 2 import com.example.calculator.R;
 3 
 4 import android.app.Activity;
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.view.Menu;
 8 import android.view.View;
 9 import android.view.View.OnClickListener;
10 import android.widget.Button;
11 import android.widget.RadioButton;
12 import android.widget.RadioGroup;
13 import android.widget.RadioGroup.OnCheckedChangeListener;
14 import android.widget.TextView;
15 
16 
17 public class panduanset extends Activity {
18     private TextView panduannumber;
19     private RadioGroup panduanRG;
20     private int i,g;
21     private Button panduanxunlian;
22     private int []number12=new int[]{0,1,2,3};
23     private RadioButton r;
24     protected void onCreate(Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         setContentView(R.layout.activity_panduan_set);
27         panduannumber=(TextView)findViewById(R.id.panduannumber);
28         panduanRG=(RadioGroup)findViewById(R.id.panduangroup);
29         panduanxunlian=(Button)findViewById(R.id.panduanxunlian);
30         panduanRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
31             
32             @Override
33             public void onCheckedChanged(RadioGroup arg0, int arg1) {
34                 // TODO Auto-generated method stub
35                 r=(RadioButton)findViewById(arg1);
36             }
37         });
38         panduanxunlian.setOnClickListener(new OnClickListener() {
39             
40             @Override
41             public void onClick(View arg0) {
42                 // TODO Auto-generated method stub
43                 for (int g=0; g<4;g++){
44                        RadioButton r=(RadioButton)panduanRG.getChildAt(g);
45                         if(r.isChecked()){
46                          i=number12[g];
47                          break;
48                         }
49                 }
50                 g=Integer.valueOf(panduannumber.getText().toString());
51                 Intent intent=new Intent();
52                 Bundle bundle=new Bundle();
53                 bundle.putInt("panduansuanfa", i);
54                 bundle.putInt("panduanshumu",g);
55                 intent.setClass(panduanset.this,panduanActivity.class);
56                 intent.putExtras(bundle);
57                 startActivity(intent);
58             }
59         });
60     }
61 
62     @Override
63     public boolean onCreateOptionsMenu(Menu menu) {
64         // Inflate the menu; this adds items to the action bar if it is present.
65         getMenuInflater().inflate(R.menu.main, menu);
66         return true;
67     }
68 
69 }
panduanset.java
activity_panduan_set.xml
 1 package com.example.calculator;
 2 
 3 import android.app.Activity;
 4 import android.content.Intent;
 5 import android.os.Bundle;
 6 import android.view.Menu;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.widget.Button;
10 import android.widget.TextView;
11 
12 public class panduanresult extends Activity{
13     private TextView t1;
14     private TextView t2;
15     protected void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.activity_panduan_result);
18         t1=(TextView)findViewById(R.id.panduan12);
19         t2=(TextView)findViewById(R.id.panduan13);
20         Bundle bundle=getIntent().getExtras();
21         int i=bundle.getInt("panduannumber");
22         String []answer=bundle.getStringArray("panduanarry");
23         String []title1=bundle.getStringArray("titlearry");
24          String aa="";
25          String aaa="";
26         for(int g=0;g<i;g++){
27             aa+=title1[g]+"\n";
28             aaa+=answer[g]+"\n";
29             t1.setText(aa);
30             t2.setText(aaa);;
31         }
32     }
33 
34     @Override
35     public boolean onCreateOptionsMenu(Menu menu) {
36         // Inflate the menu; this adds items to the action bar if it is present.
37         getMenuInflater().inflate(R.menu.main, menu);
38         return true;
39     }
40 
41 }
panduanresult.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:background="@drawable/lovely2"
 7     android:orientation="vertical" >
 8 
 9     <TextView
10         android:id="@+id/textView1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:layout_alignParentTop="true"
14         android:layout_centerHorizontal="true"
15         android:layout_marginTop="16dp"
16         android:text="@string/result"
17         android:textSize="30sp" />
18 
19     <TextView
20         android:id="@+id/textView2"
21         android:layout_width="wrap_content"
22         android:layout_height="wrap_content"
23         android:layout_below="@+id/textView1"
24         android:layout_marginTop="16dp"
25         android:layout_toLeftOf="@+id/textView1"
26         android:text="@string/number" 
27         android:textSize="20sp"/>
28 
29     <TextView
30         android:id="@+id/textView3"
31         android:layout_width="wrap_content"
32         android:layout_height="wrap_content"
33         android:layout_alignBaseline="@+id/textView2"
34         android:layout_alignBottom="@+id/textView2"
35         android:layout_toRightOf="@+id/textView1"
36         android:text="@string/panduan"
37         android:textSize="20sp" />
38 
39     <TextView
40         android:id="@+id/panduan12"
41         android:layout_width="wrap_content"
42         android:layout_height="wrap_content"
43         android:layout_alignLeft="@+id/textView2"
44         android:layout_below="@+id/textView2"
45         android:layout_marginTop="16dp"
46         android:text="TextView" />
47 
48     <TextView
49         android:id="@+id/panduan13"
50         android:layout_width="wrap_content"
51         android:layout_height="wrap_content"
52         android:layout_alignBaseline="@+id/panduan12"
53         android:layout_alignBottom="@+id/panduan12"
54         android:layout_toRightOf="@+id/textView1"
55         android:text="TextView" />
56 
57 </RelativeLayout>
activity_panduan_result.xml
  1 package com.example.calculator;
  2 
  3 import android.app.Activity;
  4 import android.app.AlertDialog;
  5 import android.app.AlertDialog.Builder;
  6 import android.app.Dialog;
  7 import android.content.DialogInterface;
  8 import android.content.Intent;
  9 import android.graphics.Canvas;
 10 import android.graphics.Color;
 11 import android.graphics.Paint;
 12 import android.graphics.Rect;
 13 import android.os.Bundle;
 14 import android.view.Menu;
 15 import android.view.MotionEvent;
 16 import android.view.SurfaceHolder;
 17 import android.view.SurfaceView;
 18 import android.view.View;
 19 import android.view.View.OnClickListener;
 20 import android.widget.Button;
 21 
 22 public class HuabuActivity extends Activity{
 23     private SurfaceView mSurfaceView;
 24     private SurfaceHolder mSurfaceHolder;
 25     private Button b1;
 26     private Button b2;
 27     private float oldX=0f;
 28     private float oldY=0f;
 29     private boolean canDraw=false;
 30     private Paint mpaint;
 31     private int whichColor=0;
 32     private Dialog mdialog;
 33     protected void onCreate(Bundle savedInstanceState) {
 34         super.onCreate(savedInstanceState);
 35         setContentView(R.layout.activity_huabu);
 36         mSurfaceView=(SurfaceView)findViewById(R.id.surfaceView1);
 37         mSurfaceHolder=mSurfaceView.getHolder();
 38         mpaint=new Paint();
 39         mpaint.setColor(Color.RED);
 40         mpaint.setStrokeWidth(2.0f);
 41         b1=(Button)findViewById(R.id.clear);
 42         b2=(Button)findViewById(R.id.color);
 43         b1.setOnClickListener(new OnClickListener() {
 44             
 45             @Override
 46             public void onClick(View arg0) {
 47                 // TODO Auto-generated method stub
 48                 Canvas mCanvas=mSurfaceHolder.lockCanvas();
 49                 mCanvas.drawColor(Color.BLACK);
 50                 mSurfaceHolder.unlockCanvasAndPost(mCanvas);
 51                 mSurfaceHolder.lockCanvas(new Rect(0,0,0,0));
 52                 mSurfaceHolder.unlockCanvasAndPost(mCanvas);
 53             }
 54         });
 55         b2.setOnClickListener(new OnClickListener() {
 56             
 57             @Override
 58             public void onClick(View arg0) {
 59                 // TODO Auto-generated method stub
 60               Dialog mdialog=new AlertDialog.Builder(HuabuActivity.this).setTitle("颜色设置").setSingleChoiceItems(new String[]{"红色","绿色","蓝色"}, whichColor,new DialogInterface.OnClickListener() {
 61                 
 62                 @Override
 63                 public void onClick(DialogInterface dialog, int which) {
 64                     // TODO Auto-generated method stub
 65                     switch(which){
 66                     case 0:
 67                     {
 68                         mpaint.setColor(Color.RED);
 69                         whichColor=0;
 70                         break;
 71                     }
 72                     case 1:
 73                     {
 74                         mpaint.setColor(Color.GREEN);
 75                         whichColor=1;
 76                         break;
 77                     }
 78                     case 2:
 79                     {
 80                         mpaint.setColor(Color.BLUE);
 81                         whichColor=2;
 82                         break;
 83                     }
 84                     }
 85                 }
 86             }).setPositiveButton("确定",new DialogInterface.OnClickListener() {
 87                 
 88                 @Override
 89                 public void onClick(DialogInterface dialog, int which) {
 90                     // TODO Auto-generated method stub
 91                     dialog.dismiss();
 92                 }
 93             }).create();
 94               mdialog.show();
 95             }
 96         });
 97     }
 98 public boolean onTouchEvent(MotionEvent event){
 99     float x=event.getX();
100     float y=event.getY()-50;
101     if(canDraw){
102         switch(event.getAction())
103         {
104         case MotionEvent.ACTION_MOVE:
105         {
106             Canvas mCanvas=mSurfaceHolder.lockCanvas();
107             mCanvas.drawLine(x, y, oldX, oldY, mpaint);
108             mSurfaceHolder.unlockCanvasAndPost(mCanvas);
109             mSurfaceHolder.lockCanvas(new Rect(0,0,0,0));
110             mSurfaceHolder.unlockCanvasAndPost(mCanvas);
111             break;
112         }    
113        }
114     }
115     oldX=x;
116     oldY=y;
117     canDraw=true;
118     return true;
119     
120 }
121     @Override
122     public boolean onCreateOptionsMenu(Menu menu) {
123         // Inflate the menu; this adds items to the action bar if it is present.
124         getMenuInflater().inflate(R.menu.main, menu);
125         return true;
126     }
127 
128 
129 }
HuabuActivity.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/AbsoluteLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent" >
 6 
 7     <SurfaceView
 8         android:id="@+id/surfaceView1"
 9         android:layout_width="match_parent"
10         android:layout_height="396dp" />
11 
12     <Button
13         android:id="@+id/clear"
14         android:layout_width="wrap_content"
15         android:layout_height="wrap_content"
16         android:layout_x="3dp"
17         android:layout_y="411dp"
18         android:text="清除" />
19 
20     <Button
21         android:id="@+id/color"
22         android:layout_width="wrap_content"
23         android:layout_height="wrap_content"
24         android:layout_x="236dp"
25         android:layout_y="410dp"
26         android:text="颜色" />
27 
28 </AbsoluteLayout>
activity_huabu.xml