1. 程式人生 > 其它 >python實戰技巧之兩個列表例項中,如何讓裡面的數字一一對應地相加【對於兩個列表是等長的情況】

python實戰技巧之兩個列表例項中,如何讓裡面的數字一一對應地相加【對於兩個列表是等長的情況】

今日看了網上的體溫開發視訊,做了一部分,包括填寫姓名,日期和體溫,以下是我的程式碼:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout tools:context="com.example.myapplication.MainActivity"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="30dp"
android:text="信1905-2學生體溫登記表"
android:textColor="@color/colorPrimaryDark"
android:textSize="35dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="15dp"
android:text="姓名:"
android:textSize="30dp"
android:textColor="@color/black"
/>
<EditText
android:layout_width="270dp"
android:layout_height="70dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:hint="請輸入你的姓名" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="15dp"
android:text="體溫:"
android:textSize="30dp"
android:textColor="@color/black"
/>
<EditText
android:layout_width="270dp"
android:layout_height="70dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:hint="請輸入今日體溫:如(36.5/36.9)" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="15dp"
android:text="填報日期:"
android:textSize="30dp"
android:textColor="@color/black"
/>
<EditText
android:id="@+id/date"
android:layout_width="210dp"
android:layout_height="70dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:hint="請輸入今日日期" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="15dp"
android:text="你的位置:"
android:textSize="30dp"
android:textColor="@color/black"
/>
<EditText
android:id="@+id/address"
android:layout_width="210dp"
android:layout_height="70dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:hint="請輸入你的地理位置" />
</LinearLayout>
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="0dp"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:text="提交"
android:textColor="#FFFFFF"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout

package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private long exitTime = 0; //退出時間變數值
private EditText text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(EditText)findViewById(R.id.date);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
startActivityForResult(new Intent(MainActivity.this, Tiwenapp.class),0x11);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==0x11 && resultCode==0x11){
Bundle bundle=data.getExtras();
String date=bundle.getString("data");
text.setText(date);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
exit();
return true; //攔截返回鍵
}
return super.onKeyDown(keyCode, event);
}
public void exit() {
if ((System.currentTimeMillis() - exitTime) > 2000) { //計算按鍵時間差是否大於兩秒
Toast.makeText(getApplicationContext(), "再按一次退出程式", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0); //銷燬強制退出
}
}
}