小学四则运算APP 最后阶段

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

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

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

运行结果如下:

小学四则运算APP 最后阶段小学四则运算APP 最后阶段

小学四则运算APP 最后阶段小学四则运算APP 最后阶段

小学四则运算APP 最后阶段小学四则运算APP 最后阶段

小学四则运算APP 最后阶段

 package com.example.calculator;

 import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity { private Button xunlian;
private Button panduan;
private Button xuanze; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xunlian=(Button)findViewById(R.id.button1);
panduan=(Button)findViewById(R.id.button4);
xuanze=(Button)findViewById(R.id.button2);
xunlian.setOnClickListener(new OnClickListener() {//填空题 @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this, CalculatorSet.class);
startActivity(intent);
MainActivity.this.finish();
}
});
panduan.setOnClickListener(new OnClickListener() {//判断题 @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent2=new Intent();
intent2.setClass(MainActivity.this,panduanset.class);
startActivity(intent2);
MainActivity.this.finish();
}
});
xuanze.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent3=new Intent();
intent3.setClass(MainActivity.this, ChoiceSet.class);
startActivity(intent3);
MainActivity.this.finish();
}
});
} @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;
} }

MainActivity.java

 <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:background="@drawable/lovely3"
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/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="93dp"
android:text="@string/hello_world"
android:textSize="@dimen/btnTextSize" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="44dp"
android:text="进入普通训练系统"
android:textSize="@dimen/btnTextSizes" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/button1"
android:text="@string/panduan1"
android:textSize="@dimen/btnTextSizes" /> <Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_below="@+id/button4"
android:text="进入选择题训练系统"
android:textSize="@dimen/btnTextSizes" /> <Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button2"
android:text="进入考试题目系统"
android:textSize="@dimen/btnTextSizes" /> </RelativeLayout>

activity_main.xml

 package com.example.calculator;

 import java.text.ChoiceFormat;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class CalculatorSet extends Activity{
private TextView number;
private RadioGroup radio;
private RadioButton r;
private int i=0,g;
private Button xunlian;
private int []number1=new int[]{0,1,2,3};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activtity_calculator_set);
number=(TextView)findViewById(R.id.number1);
radio=(RadioGroup)findViewById(R.id.group);
xunlian=(Button)findViewById(R.id.xunlian);
radio.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
r=(RadioButton)findViewById(arg1);
}
});
xunlian.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
for (int g=0; g<4;g++){
RadioButton r=(RadioButton)radio.getChildAt(g);
if(r.isChecked()){
i=number1[g];
break;
} }
g=Integer.valueOf(number.getText().toString());
Intent intent=new Intent();
Bundle bundle=new Bundle();
bundle.putInt("suanfa", i);
bundle.putInt("shumu",g);
intent.setClass(CalculatorSet.this,CalculatorActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
} @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;
} }

CalculatorSet.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:background="@drawable/lovely1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="@string/title_activity_set"
android:textSize="30sp" /> <RadioGroup
android:id="@+id/panduangroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="125dp"
android:orientation="horizontal" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" /> <RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radio0"
android:layout_below="@+id/radio0"
android:text="@string/jian" /> <RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cheng" /> <RadioButton
android:id="@+id/radio4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chu" />
</RadioGroup> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="14dp"
android:layout_marginTop="41dp"
android:text="@string/the_number_of_calculator"
android:textSize="20sp" /> <EditText
android:id="@+id/panduannumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:ems="10"
android:inputType="number" /> <Button
android:id="@+id/panduanxunlian"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/panduannumber"
android:layout_below="@+id/panduangroup"
android:layout_marginTop="74dp"
android:text="训练开始" /> </RelativeLayout>

activity_calculator_set.xml

 package com.example.calculator;

 import java.util.Random;

 import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
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 CalculatorActivity extends Activity {
private final Random num1=new Random();
private final Random num2=new Random();
private final Random r = new Random();
private Button next;
private char[] ch = {'+','-','*','/'};//字符数组
//private int[]puanduan;
private int index; //随机数,小于数组的长度数, 0~3
private char a;
private TextView text1,text2,text3;
private EditText answer;
private Button surebutton;//确定按钮
private Button caogaozhi;//草稿纸
private int i,m=0;
private String c;
private String e;
private String b;
private int i1,i2,i3;
private int n=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculator);
Bundle bundle=getIntent().getExtras();
index=bundle.getInt("suanfa");
a=ch[index];
i=bundle.getInt("shumu");
final String[]puanduan=new String[i];
final String[]title1=new String[100];
text1=(TextView)findViewById(R.id.textView1);//随机数字
text2=(TextView)findViewById(R.id.textView2);//运算符号
text3=(TextView)findViewById(R.id.textView3);//随机数字
answer=(EditText)findViewById(R.id.editText1);//运算结果
next=(Button)findViewById(R.id.next);
caogaozhi=(Button)findViewById(R.id.caogaozhi);
String c=String.valueOf(num1.nextInt(100));
i2=Integer.valueOf(c);
String d=String.valueOf(a);
String e=String.valueOf(num2.nextInt(100));
i3=Integer.valueOf(e);
text1.setText(c);//随机数1-100
text2.setText(d);//随机运算符+,-,*,/
text3.setText(e);//随机数1-100
title1[n]=c+d+e;
n++;
surebutton=(Button)findViewById(R.id.surebutton);//确定按钮
surebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
final String b=answer.getText().toString();//获取输入的数值
i1=Integer.valueOf(b);
switch(index){
case 0:
{
if(i1==(i2+i3))
{
Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="正确";
}
else
{
Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="错误";
}
break;
}
case 1:
{
if(i1==(i2-i3))
{
Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="正确";
}
else
{
Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="错误";
}
break;
}
case 2:{
if(i1==(i2*i3))
{
Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="正确";
}
else
{
Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="错误";
}
break;
}
case 3:
{
if(i3!=0){
if(i1==(i2/i3))
{
Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="正确";
}
else
{
Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
puanduan[m]="错误";
}
}
break;
}
}
i--;
m++;
if(i==0){
Toast.makeText(CalculatorActivity.this,"已经到了了题目个数!",Toast.LENGTH_LONG ).show(); }
else{
String c=String.valueOf(num1.nextInt(100));
i2=Integer.valueOf(c);
String d=String.valueOf(a);
String e=String.valueOf(num2.nextInt(100));
i3=Integer.valueOf(e);
text1.setText(c);//随机数1-100
text2.setText(d);//随机运算符+,-,*,/
text3.setText(e);//随机数1-100
title1[n]=c+d+e;
n++;
answer.setText(null);
}
}
});
next.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
if(i==0){
Intent intent=new Intent();
Bundle bundle2=new Bundle();
bundle2.putStringArray("panduan", puanduan);
bundle2.putStringArray("titlearry", title1);
bundle2.putInt("number", m);
intent.putExtras(bundle2);
intent.setClass(CalculatorActivity.this,resultActivity.class);
startActivity(intent);
CalculatorActivity.this.finish();
}
else
Toast.makeText(CalculatorActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show();
}
});
caogaozhi.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(CalculatorActivity.this, HuabuActivity.class);
startActivity(intent);
CalculatorActivity.this.finish();
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.calculator, menu);
return true;
} }

CalculatorActivity.java

 <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:background="@drawable/lovely3"
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=".CalculatorActivity" > <TextView
android:id="@+id/textView1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="100dp" /> <TextView
android:id="@+id/textView2"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_toRightOf="@+id/textView1" /> <TextView
android:id="@+id/textView3"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2" /> <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="=" /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_marginLeft="38dp"
android:layout_toRightOf="@+id/textView4"
android:ems="10"
android:inputType="number" > <requestFocus />
</EditText> <Button
android:id="@+id/surebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText1"
android:layout_marginTop="88dp"
android:text="确定" /> <Button
android:id="@+id/caogaozhi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/next"
android:layout_alignRight="@+id/surebutton"
android:layout_below="@+id/surebutton"
android:text="草稿纸" /> <Button
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/surebutton"
android:layout_alignRight="@+id/surebutton"
android:layout_below="@+id/caogaozhi"
android:text="打印分数" /> </RelativeLayout>

activity_calculator.xml

 package com.example.calculator;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener; public class resultActivity extends Activity {
private TextView number;
private TextView panduan;
//private TextView sum;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
Bundle bundle=getIntent().getExtras();
number=(TextView)findViewById(R.id.thenumber);
panduan=(TextView)findViewById(R.id.pan);
int i=bundle.getInt("number");
String []puanduan=bundle.getStringArray("panduan");
String []title1=bundle.getStringArray("titlearry");
String aa="";
String aaa="";
for(int g=0;g<i;g++){
aa+=title1[g]+"\n";
aaa+=puanduan[g]+"\n";
number.setText(aa);
panduan.setText(aaa);;
}
} @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;
} }

resultActivity.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/lovely2"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="@string/result"
android:textSize="30sp"/> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView1"
android:text="@string/panduan"
android:textSize="20sp" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="14dp"
android:layout_toLeftOf="@+id/textView1"
android:text="@string/number"
android:textSize="20sp" /> <TextView
android:id="@+id/thenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="TextView" /> <TextView
android:id="@+id/pan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/thenumber"
android:layout_alignBottom="@+id/thenumber"
android:layout_toRightOf="@+id/textView1"
android:text="TextView" /> </RelativeLayout>

activity_result.xml

 package com.example.calculator;

 import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener; public class ChoiceSet extends Activity {
private TextView number;
private int i=0,g;
private Button xunlian; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice_set);
number=(TextView)findViewById(R.id.number1);
xunlian=(Button)findViewById(R.id.xunlian); xunlian.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub g=Integer.valueOf(number.getText().toString());
Intent intent=new Intent();
Bundle bundle=new Bundle();
bundle.putInt("shumu",g);
intent.setClass(ChoiceSet.this,ChoiceActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.choice_set, menu);
return true;
} }

ChoiceSet.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:background="@drawable/lovely1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="@string/title_activity_set"
android:textSize="30sp" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="14dp"
android:layout_marginTop="41dp"
android:text="@string/the_number_of_calculator"
android:textSize="20sp" /> <EditText
android:id="@+id/panduannumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:ems="10"
android:inputType="number" /> <Button
android:id="@+id/panduanxunlian"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/panduannumber"
android:layout_below="@+id/panduangroup"
android:layout_marginTop="74dp"
android:text="训练开始" /> </RelativeLayout>

activity_choice_set.xml

 package com.example.calculator;

 import java.util.Random;

 import android.os.Bundle;
import android.app.Activity;
import android.view.Menu; import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast; public class ChoiceActivity extends Activity { private TextView text1,text2,text3;
private CheckBox checkbox1,checkbox2,checkbox3,checkbox4;
private Button btn1,btn2,caogaozhi;
private int i,m=0;
private int n=0;
private final Random num1=new Random();
private final Random num2=new Random();
private final Random num3=new Random();
private final Random num4=new Random();
private final Random num5=new Random();
private final Random r = new Random();
private int x1;
private int x2;
private int x3; private char[] ch={'+','-','*','/'}; //字符数组
private int index = r.nextInt(ch.length); //随机数,小于数组的长度数, 0~3
private char x;
private char d; @Override
protected void onCreate(Bundle savedInstanceState) {
ActionBar actionBar=getActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice);
Bundle bundle=getIntent().getExtras();
index=bundle.getInt("suanfa");
d=ch[index];
i=bundle.getInt("shumu");
final String[]puanduan=new String[i];
final String[]title1=new String[100]; text1=(TextView)findViewById(R.id.textView1);
text2=(TextView)findViewById(R.id.textView2);
text3=(TextView)findViewById(R.id.textView3); checkbox1=(CheckBox)findViewById(R.id.checkBox1);
checkbox2=(CheckBox)findViewById(R.id.checkBox2);
checkbox3=(CheckBox)findViewById(R.id.checkBox3);
checkbox4=(CheckBox)findViewById(R.id.checkBox4);
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
caogaozhi=(Button)findViewById(R.id.caogaozhi3); final String a=String.valueOf(num1.nextInt(100));
x1=Integer.valueOf(a);
final String b=String.valueOf(num2.nextInt(100));
x2=Integer.valueOf(b);
final String c=String.valueOf(num3.nextInt(100));
final String f=String.valueOf(num4.nextInt(100));
final String z=String.valueOf(num5.nextInt(100));
final String e=String.valueOf(d); text1.setText(a);
text3.setText(b);
text2.setText(e); checkbox1.setText(f);
checkbox2.setText(z);
checkbox4.setText(c); if(index==0){
x3=x1+x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==1){
x3=x1-x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==2){
x3=x1*x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==3){
x3=x1/x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
} //"确定"按钮
btn1.setOnClickListener(new OnClickListener() { final String h=String.valueOf(x3); @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub if(checkbox3.isChecked()){
Toast.makeText(ChoiceActivity.this, "正确", Toast.LENGTH_SHORT).show();
puanduan[m]="正确";
}
if(!(checkbox3.isChecked())){
Toast.makeText(ChoiceActivity.this, "错误"+h, Toast.LENGTH_SHORT).show();
puanduan[m]="错误";
}
i--;
m++;
if(i==0){
Toast.makeText(ChoiceActivity.this,"已经到了了题目个数!",Toast.LENGTH_LONG ).show(); }
else{
final String a=String.valueOf(num1.nextInt(100));
x1=Integer.valueOf(a);
final String b=String.valueOf(num2.nextInt(100));
x2=Integer.valueOf(b);
final String c=String.valueOf(num3.nextInt(100));
final String f=String.valueOf(num4.nextInt(100));
final String z=String.valueOf(num5.nextInt(100));
final String e=String.valueOf(d); title1[n]=c+d+e;
n++; text1.setText(a);
text3.setText(b);
text2.setText(e); checkbox1.setText(f);
checkbox2.setText(z);
checkbox4.setText(c); if(index==0){
x3=x1+x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==1){
x3=x1-x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==2){
x3=x1*x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
if(index==3){
x3=x1/x2;
final String h=String.valueOf(x3);
checkbox3.setText(h);
}
} }
}); btn2.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
if(i==0){
Intent intent=new Intent();
Bundle bundle2=new Bundle();
bundle2.putStringArray("panduan", puanduan);
bundle2.putStringArray("titlearry", title1);
bundle2.putInt("number", m);
intent.putExtras(bundle2);
intent.setClass(ChoiceActivity.this,ChoiceResult.class);
startActivity(intent);
ChoiceActivity.this.finish();
}
else
Toast.makeText(ChoiceActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show();
}
}); caogaozhi.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(ChoiceActivity.this, HuabuActivity.class);
startActivity(intent);
ChoiceActivity.this.finish();
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.choice, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case android.R.id.home:
//创建启动MainActivity的Intent
Intent intent=new Intent(this,MainActivity.class);
//添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break; default:
break;
}
return super.onOptionsItemSelected(item);
} }

ChoiceActivity.java

 <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:background="@drawable/lovely3"
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=".ChoiceActivity" > <TextView
android:id="@+id/textView1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="100dp" /> <TextView
android:id="@+id/textView2"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_toRightOf="@+id/textView1" /> <TextView
android:id="@+id/textView3"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2" /> <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="=" /> <TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_toLeftOf="@+id/checkBox1"
android:text="A" /> <TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox2"
android:layout_alignBottom="@+id/checkBox2"
android:layout_alignRight="@+id/textView5"
android:text="B" /> <TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox3"
android:layout_alignBottom="@+id/checkBox3"
android:layout_toLeftOf="@+id/checkBox3"
android:text="C" /> <TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox4"
android:layout_alignBottom="@+id/checkBox4"
android:layout_toLeftOf="@+id/checkBox4"
android:text="D" /> <CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox3"
android:layout_below="@+id/checkBox3" /> <CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView4"
android:layout_centerVertical="true" /> <CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox1"
android:layout_below="@+id/checkBox1" /> <CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox2"
android:layout_below="@+id/checkBox2" /> <Button
android:id="@+id/caogaozhi3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:text="草稿纸" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/checkBox4"
android:layout_marginTop="26dp"
android:text="确定" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/textView8"
android:text="打印" /> </RelativeLayout>

activity_choice.xml

 package com.example.calculator;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; public class ChoiceResult extends Activity{
private TextView t1;
private TextView t2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice_result);
t1=(TextView)findViewById(R.id.panduan12);
t2=(TextView)findViewById(R.id.panduan13);
Bundle bundle=getIntent().getExtras();
int i=bundle.getInt("panduannumber");
String []answer=bundle.getStringArray("panduanarry");
String []title1=bundle.getStringArray("titlearry");
String aa="";
String aaa="";
for(int g=0;g<i;g++){
aa+=title1[g]+"\n";
aaa+=answer[g]+"\n";
t1.setText(aa);
t2.setText(aaa);;
}
} @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;
} }

ChoiceResult.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/lovely2"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="@string/result"
android:textSize="30sp"/> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView1"
android:text="@string/panduan"
android:textSize="20sp" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="14dp"
android:layout_toLeftOf="@+id/textView1"
android:text="@string/number"
android:textSize="20sp" /> <TextView
android:id="@+id/thenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="TextView" /> <TextView
android:id="@+id/pan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/thenumber"
android:layout_alignBottom="@+id/thenumber"
android:layout_toRightOf="@+id/textView1"
android:text="TextView" /> </RelativeLayout>

activity_choice_result.xml

 package com.example.calculator;

 import java.util.Random;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class panduanActivity extends Activity{
private Button next1;
private Button result1;
private Button caogaozhi;
private RadioGroup panduan;
private int []number12=new int[]{0,1};
private RadioButton m;
private TextView timu1;
private int index,i;
private int k,j,l,sum,wrong,right,sign=0,label=0,n=0;
private char a;
private final Random num1=new Random();
private final Random num2=new Random();
private final Random r = new Random();
private char[] ch = {'+','-','*','/'};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panduan);
panduan=(RadioGroup)findViewById(R.id.group2);
next1=(Button)findViewById(R.id.next1);
result1=(Button)findViewById(R.id.result1);
timu1=(TextView)findViewById(R.id.timu1);
caogaozhi=(Button)findViewById(R.id.caogaozhi2);
Bundle bundle=getIntent().getExtras();
index=bundle.getInt("panduansuanfa");
a=ch[index];
i=bundle.getInt("panduanshumu");
final String[] title1=new String[100];
final String []answer=new String[i];
String c=String.valueOf(num1.nextInt(100));
String b=String.valueOf(num2.nextInt(100));
String g=String.valueOf(r.nextInt(3));
k=Integer.valueOf(g);
l=Integer.valueOf(c);
j=Integer.valueOf(b);
String d=String.valueOf(a);
switch(index){
case 0:
sum=l+j;
break;
case 1:
sum=l-j;
break;
case 2:
sum=l*j;
break;
case 4:
sum=l/j;
break;
}
switch(k){
case 0:
timu1.setText(c+d+b+"="+String.valueOf(sum));
title1[n]=c+d+b+"="+String.valueOf(sum);
n++;
right=0;
break;
case 1:
timu1.setText(c+d+b+"="+String.valueOf(sum+1));
title1[n]=c+d+b+"="+String.valueOf(sum+1);
n++;
right=1;
break;
case 2:
timu1.setText(c+d+b+"="+String.valueOf(sum+2));
title1[n]=c+d+b+"="+String.valueOf(sum+2);
n++;
right=1;
break;
default:
break;
}
panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
m=(RadioButton)findViewById(arg1);
}
});
next1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
for (int g=0; g<2;g++){
RadioButton m=(RadioButton)panduan.getChildAt(g);
if(m.isChecked()){
sign=number12[g];
break;
}
}
if(i!=0){
if(sign==right){
Toast.makeText(panduanActivity.this, "选择正确", Toast.LENGTH_LONG).show();
answer[label]="right";
}
if(sign!=right){
Toast.makeText(panduanActivity.this, "选择错误", Toast.LENGTH_LONG).show();
answer[label]="wrong";
}
i--;
label++;
String c=String.valueOf(num1.nextInt(100));
String b=String.valueOf(num2.nextInt(100));
String g=String.valueOf(r.nextInt(3));
k=Integer.valueOf(g);
l=Integer.valueOf(c);
j=Integer.valueOf(b);
String d=String.valueOf(a);
switch(index){
case 0:
sum=l+j;
break;
case 1:
sum=l-j;
break;
case 2:
sum=l*j;
break;
case 4:
sum=l/j;
break;
}
switch(k){
case 0:
timu1.setText(c+d+b+"="+String.valueOf(sum));
title1[n]=c+d+b+"="+String.valueOf(sum);
n++;
right=0;
break;
case 1:
timu1.setText(c+d+b+"="+String.valueOf(sum+1));
title1[n]=c+d+b+"="+String.valueOf(sum+1);
n++;
right=1;
break;
case 2:
timu1.setText(c+d+b+"="+String.valueOf(sum+2));
title1[n]=c+d+b+"="+String.valueOf(sum+2);
n++;
right=1;
break;
default:
break;
}
panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
m=(RadioButton)findViewById(arg1);
}
});
}
else
{
Toast.makeText(panduanActivity.this,"题目已做完", Toast.LENGTH_LONG).show();
timu1.setText(null);
}
}
});
result1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
if(i!=0)
Toast.makeText(panduanActivity.this, "题目没有做完,请继续完成", Toast.LENGTH_LONG).show();
else{
Intent intent=new Intent();
Bundle bundle2=new Bundle();
intent.setClass(panduanActivity.this,panduanresult.class);
bundle2.putInt("panduannumber", label);
bundle2.putStringArray("panduanarry", answer);
bundle2.putStringArray("titlearry", title1);
intent.putExtras(bundle2);
startActivity(intent);
} }
});
caogaozhi.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(panduanActivity.this, HuabuActivity.class);
startActivity(intent);
panduanActivity.this.finish();
}
});
} @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;
} }

panduanActivity.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/lovely3"
android:orientation="vertical" > <TextView
android:id="@+id/timu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="17dp"
android:layout_toRightOf="@+id/textView1"
android:text="TextView"
android:textSize="20sp"/> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:text="题目:"
android:textSize="20sp" /> <RadioGroup
android:id="@+id/group2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/timu1"
android:layout_marginTop="38dp"
android:orientation="vertical" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/right"
android:textSize="20sp" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radio0"
android:layout_below="@+id/radio0"
android:text="@string/wrong"
android:textSize="20sp" />
</RadioGroup> <Button
android:id="@+id/caogaozhi2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/result1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="草稿纸" /> <Button
android:id="@+id/next1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="51dp"
android:text="下一题" /> <Button
android:id="@+id/result1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/next1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="结果输出" /> </RelativeLayout>

activity_panduan.xml

 package com.example.calculator;
import com.example.calculator.R; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class panduanset extends Activity {
private TextView panduannumber;
private RadioGroup panduanRG;
private int i,g;
private Button panduanxunlian;
private int []number12=new int[]{0,1,2,3};
private RadioButton r;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panduan_set);
panduannumber=(TextView)findViewById(R.id.panduannumber);
panduanRG=(RadioGroup)findViewById(R.id.panduangroup);
panduanxunlian=(Button)findViewById(R.id.panduanxunlian);
panduanRG.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
r=(RadioButton)findViewById(arg1);
}
});
panduanxunlian.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
for (int g=0; g<4;g++){
RadioButton r=(RadioButton)panduanRG.getChildAt(g);
if(r.isChecked()){
i=number12[g];
break;
}
}
g=Integer.valueOf(panduannumber.getText().toString());
Intent intent=new Intent();
Bundle bundle=new Bundle();
bundle.putInt("panduansuanfa", i);
bundle.putInt("panduanshumu",g);
intent.setClass(panduanset.this,panduanActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
} @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;
} }

panduanset.java

activity_panduan_set.xml
 package com.example.calculator;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; public class panduanresult extends Activity{
private TextView t1;
private TextView t2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panduan_result);
t1=(TextView)findViewById(R.id.panduan12);
t2=(TextView)findViewById(R.id.panduan13);
Bundle bundle=getIntent().getExtras();
int i=bundle.getInt("panduannumber");
String []answer=bundle.getStringArray("panduanarry");
String []title1=bundle.getStringArray("titlearry");
String aa="";
String aaa="";
for(int g=0;g<i;g++){
aa+=title1[g]+"\n";
aaa+=answer[g]+"\n";
t1.setText(aa);
t2.setText(aaa);;
}
} @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;
} }

panduanresult.java

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/lovely2"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="@string/result"
android:textSize="30sp" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="16dp"
android:layout_toLeftOf="@+id/textView1"
android:text="@string/number"
android:textSize="20sp"/> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView1"
android:text="@string/panduan"
android:textSize="20sp" /> <TextView
android:id="@+id/panduan12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="16dp"
android:text="TextView" /> <TextView
android:id="@+id/panduan13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/panduan12"
android:layout_alignBottom="@+id/panduan12"
android:layout_toRightOf="@+id/textView1"
android:text="TextView" /> </RelativeLayout>

activity_panduan_result.xml

 package com.example.calculator;

 import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class HuabuActivity extends Activity{
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private Button b1;
private Button b2;
private float oldX=0f;
private float oldY=0f;
private boolean canDraw=false;
private Paint mpaint;
private int whichColor=0;
private Dialog mdialog;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_huabu);
mSurfaceView=(SurfaceView)findViewById(R.id.surfaceView1);
mSurfaceHolder=mSurfaceView.getHolder();
mpaint=new Paint();
mpaint.setColor(Color.RED);
mpaint.setStrokeWidth(2.0f);
b1=(Button)findViewById(R.id.clear);
b2=(Button)findViewById(R.id.color);
b1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Canvas mCanvas=mSurfaceHolder.lockCanvas();
mCanvas.drawColor(Color.BLACK);
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
mSurfaceHolder.lockCanvas(new Rect(0,0,0,0));
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
}
});
b2.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Dialog mdialog=new AlertDialog.Builder(HuabuActivity.this).setTitle("颜色设置").setSingleChoiceItems(new String[]{"红色","绿色","蓝色"}, whichColor,new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch(which){
case 0:
{
mpaint.setColor(Color.RED);
whichColor=0;
break;
}
case 1:
{
mpaint.setColor(Color.GREEN);
whichColor=1;
break;
}
case 2:
{
mpaint.setColor(Color.BLUE);
whichColor=2;
break;
}
}
}
}).setPositiveButton("确定",new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
}).create();
mdialog.show();
}
});
}
public boolean onTouchEvent(MotionEvent event){
float x=event.getX();
float y=event.getY()-50;
if(canDraw){
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
{
Canvas mCanvas=mSurfaceHolder.lockCanvas();
mCanvas.drawLine(x, y, oldX, oldY, mpaint);
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
mSurfaceHolder.lockCanvas(new Rect(0,0,0,0));
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
break;
}
}
}
oldX=x;
oldY=y;
canDraw=true;
return true; }
@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;
} }

HuabuActivity.java

 <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" > <SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="match_parent"
android:layout_height="396dp" /> <Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="3dp"
android:layout_y="411dp"
android:text="清除" /> <Button
android:id="@+id/color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="236dp"
android:layout_y="410dp"
android:text="颜色" /> </AbsoluteLayout>

activity_huabu.xml

上一篇:安装yii2 需要token 记录


下一篇:UVa 116 单向TSP(多段图最短路)