团队成员:陈淑筠、杨家安、陈曦
团队选题:小学四则运算APP
第二次冲刺阶段时间:11.29~12.09
本次发布的是合并后的选择题功能界面的设置:
ChoiceSet.java:
package com.example.calculatorjiaan; 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.TextView; public class ChoiceSet extends Activity { private TextView number; private int 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; } }
activity_choice_set.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".ChoiceSet" > <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/number1" 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/xunlian" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/number1" android:layout_marginBottom="136dp" android:text="训练开始" /> </RelativeLayout>
ChoiceActivity.java:
package com.example.calculatorjiaan; import java.util.Random; 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; private int i,m=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(); d=ch[index]; 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); 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); i=bundle.getInt("shumu"); final String[]puanduan=new String[i]; 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); 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.putInt("number", m); intent.putExtras(bundle2); intent.setClass(ChoiceActivity.this,ResultsActivity.class); startActivity(intent); ChoiceActivity.this.finish(); } else Toast.makeText(ChoiceActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show(); } }); } @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); } }
activity_choice.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".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/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/checkBox4" android:layout_marginTop="24dp" android:layout_toRightOf="@+id/textView1" android:text="确定" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/checkBox4" android:text="打印" /> </RelativeLayout>
ResultsActivity.java:
package com.example.calculatorjiaan; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.TextView; public class ResultsActivity extends Activity { private TextView number; private TextView panduan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_results); 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 aa=""; String aaa=""; for(int g=0;g<i;g++){ aa+=String.valueOf(g+1)+" "; aaa+=puanduan[g]+" "; 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.results, menu); return true; } }
activity_results.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".ResultsActivity" > <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>