標籤:
團隊成員:陳淑筠、楊家安、陳曦
團隊選題:小學四則運算APP
第一次衝刺階段時間:11.17~11.27
本次發布的是重新排列整齊ResultActivity的布局代碼activity_result.xml
代碼如下:
activity_result.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" android:scrollbars="vertical" tools:context=".ResultActivity" > <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/sum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="44dp" android:text="TextView" 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="23dp" android:text="TextView" /> <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_alignRight="@+id/panduan" 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="16dp" android:layout_toLeftOf="@+id/textView1" android:text="@string/number" android:textSize="20sp" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView5" android:layout_alignBaseline="@+id/textView3" android:layout_alignBottom="@+id/textView3" android:layout_alignRight="@+id/sum" android:text="@string/trueresult" android:textSize="20sp" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/thenumber" android:layout_alignBottom="@+id/thenumber" android:layout_centerHorizontal="true" android:text="TextView" /> <TextView android:id="@+id/panduan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView5" android:layout_alignBottom="@+id/textView5" android:layout_toRightOf="@+id/textView1" android:text="TextView" /></RelativeLayout>
ResultActivity.java:
package com.example.calculator;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.TextView;public class ResultActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {ActionBar actionBar=getActionBar();actionBar.setDisplayShowHomeEnabled(true);actionBar.setDisplayHomeAsUpEnabled(true);super.onCreate(savedInstanceState);setContentView(R.layout.activity_result);Intent inten=getIntent();Bundle bundle=inten.getExtras();TextView text1=(TextView)findViewById(R.id.thenumber);TextView text=(TextView)findViewById(R.id.panduan);TextView text2=(TextView)findViewById(R.id.sum);TextView text3=(TextView)findViewById(R.id.textView5);int[] shu1=inten.getIntArrayExtra("shu1");int[] shu2=inten.getIntArrayExtra("shu2");int[] result=inten.getIntArrayExtra("result");int suanfa=bundle.getInt("suanfa");String time=bundle.getString("time");String showfa="";if(suanfa==1){showfa="+";}if(suanfa==2){showfa="-";}if(suanfa==3){showfa="*";}if(suanfa==4){showfa="/";}String[] user=inten.getStringArrayExtra("user");String aaa="";String bbb="";String ccc="";int score=0;String show4;String[] jie=new String[]{"正確","錯誤"};for (int i=0;i<shu1.length;i++){String show1="";String show2="";String show3="";show1=Integer.toString(shu1[i]);show2=Integer.toString(shu2[i]);show3=Integer.toString(result[i]);if(user[i].equals(show3)){show4=jie[0];score++;}else { show4=jie[1];}aaa+=show4+"\n";bbb+=show1+showfa+show2+"="+show3+"\n";ccc+=user[i]+"\n";text.setText(aaa);text1.setText(bbb);text3.setText(ccc);}text2.setText(time+"總得分為"+score*10);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.result, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()) {case android.R.id.home://建立啟動MainActivity的IntentIntent intent=new Intent(this,CalculatorsActivity.class);//添加額外的Flag,將Activity棧中處於MainActivity之上的Activity彈出intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(intent);break;default:break;}return super.onOptionsItemSelected(item);}}
總結:布局代碼未出錯,可是運行時“正確答案”卻和“判斷”重疊了,我們將繼續研究,解決當前問題!
小學四則運算APP 第一個衝刺階段 第六天