Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 #302 提交实验五代码 #1184

Merged
merged 4 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions students/soft1714080902311/实验五/SecondActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package edu.hzuapps.androidlabs.soft1714080902311;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.FileOutputStream;

public class SecondActivity extends AppCompatActivity {
private EditText editText3;
private EditText editText1;
private EditText editText2;
private Button button9;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
//获取布局文件
editText3 = (EditText) findViewById(R.id.editText3);
editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);
button9 = (Button) findViewById((R.id.button9));
button9.setOnClickListener(new ButtonListener());
}
//定义Button按钮的点击事件
private class ButtonListener implements View.OnClickListener{
public void onClick(View v){
switch(v.getId()){
case R.id.button9:
String saveinfo=editText3.getText().toString().trim();
String saveinfo1=editText1.getText().toString().trim();
String saveinfo2=editText2.getText().toString().trim();
FileOutputStream fos;
try{
//保存数据
fos=openFileOutput("data.text", Context.MODE_APPEND);
fos.write(saveinfo1.getBytes());
fos.write(saveinfo2.getBytes());
fos.write(saveinfo.getBytes());
fos.close();
} catch(Exception e){
e.printStackTrace();;
}
Toast.makeText(SecondActivity.this,"数据保存成功",0).show();
break;
default:
break;

}
}


}
}
63 changes: 63 additions & 0 deletions students/soft1714080902311/实验五/activity_second.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">

<LinearLayout
android:layout_width="406dp"
android:layout_height="66dp"
android:orientation="horizontal"
tools:layout_editor_absoluteX="5dp"
tools:layout_editor_absoluteY="16dp">

<EditText
android:id="@+id/editText1"
android:layout_width="164dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:text="城市:"
tools:text="@tools:sample/cities" />

<EditText
android:id="@+id/editText2"
android:layout_width="182dp"
android:layout_height="66dp"
android:layout_weight="1"
android:ems="10"
android:inputType="date"
android:text="日期:"
tools:text="@tools:sample/date/ddmmyy" />
</LinearLayout>

<LinearLayout
android:layout_width="395dp"
android:layout_height="633dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="90dp">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:text="保存" />

<EditText
android:id="@+id/editText3"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_weight="1"
android:ems="10"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>