团队成员:陈淑筠、杨家安、陈曦
团队选题:小学四则运算APP
第一次冲刺阶段时间:11.17~11.27
本次发布的是还未完成的功能二(选择题):
ChoiceActivity.java:
package com.example.calculator; 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.widget.Button; import android.widget.RadioButton; import android.widget.TextView; public class ChoiceActivity extends Activity { private TextView text1,text2,text3; private RadioButton radioButton1,radioButton2,radioButton3,radioButton4; private Button btn; private final Random num1=new Random(); private final Random num2=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 d=ch[index]; @Override protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar=getActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); super.onCreate(savedInstanceState); setContentView(R.layout.activity_choice); text1=(TextView)findViewById(R.id.textView1); text2=(TextView)findViewById(R.id.textView2); text3=(TextView)findViewById(R.id.textView3); radioButton1=(RadioButton)findViewById(R.id.radioButton1); radioButton2=(RadioButton)findViewById(R.id.radioButton2); radioButton3=(RadioButton)findViewById(R.id.radioButton3); radioButton4=(RadioButton)findViewById(R.id.radioButton4); btn=(Button)findViewById(R.id.button1); 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 e=String.valueOf(d); text1.setText(a); text3.setText(b); text2.setText(e); radioButton1.setText(a); radioButton2.setText(b); } @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,TypesActivity.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" android:background="@drawable/animal" 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="=" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/radioButton1" android:layout_centerVertical="true" /> <RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView3" android:layout_below="@+id/radioButton2" /> <RadioButton android:id="@+id/radioButton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/radioButton3" android:layout_below="@+id/radioButton3" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/radioButton4" android:layout_centerHorizontal="true" android:layout_marginTop="46dp" android:text="确定" /> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/radioButton2" android:layout_toLeftOf="@+id/button1" /> </RelativeLayout>
运行结果: