标签:
团队成员:陈淑筠、杨家安、陈曦
团队选题:小学四则运算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 { @Override protected 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); } @Override public 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; } @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,CalculatorsActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: break; } return super.onOptionsItemSelected(item); } }
总结:布局代码未出错,可是运行时“正确答案”却和“判断”重叠了,我们将继续研究,解决当前问题!
标签:
原文地址:http://www.cnblogs.com/babybluecsj/p/4993136.html