Skip to content

Commit

Permalink
Merge pull request #1202 from yingbabywhen/master
Browse files Browse the repository at this point in the history
#5  提交实验五代码
  • Loading branch information
zengsn authored Apr 2, 2019
2 parents 0861fe5 + 4fb6211 commit ca77bb6
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.soft1714080902309">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1714080902309Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package edu.hzuapps.androidlabs.soft1714080902309;

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

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Soft1714080902309Activity extends AppCompatActivity {

private EditText et_info;
private Button btn_save;
private Button btn_read;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902309_activity);
//获取布局文件中的控件
et_info = (EditText) findViewById(R.id.et_info);
btn_save = (Button) findViewById(R.id.btn_save);
btn_read = (Button) findViewById(R.id.btn_read);
//设置按钮点击函数
btn_save.setOnClickListener(new ButtonListener());
btn_read.setOnClickListener(new ButtonListener());
}

//定义Button按钮点击事件
private class ButtonListener implements View.OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_save:
String saveinfo = et_info.getText().toString().trim();
FileOutputStream fileOutputStream;
try {
fileOutputStream=openFileOutput("data.txt", Context.MODE_APPEND);
fileOutputStream.write(saveinfo.getBytes());
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(Soft1714080902309Activity.this,"谢谢您的建议!",Toast.LENGTH_SHORT).show();
break;

case R.id.btn_read:
String content="";
try{
FileInputStream fileInputStream=openFileInput("data.txt");
byte[] buffer=new byte[fileInputStream.available()];
fileInputStream.read(buffer);
content=new String(buffer);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(Soft1714080902309Activity.this,"您提的建议我们已经采纳:"+content,Toast.LENGTH_SHORT).show();
break;


default: break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".Soft1714080902309Activity">

<TextView
android:layout_width="match_parent"
android:layout_height="49dp"
android:text="建议反馈"
android:textSize="25dp"
android:gravity="center"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginTop="80dp"
android:gravity="left"
android:text="请在下方填写您宝贵的建议:"
android:textSize="20dp" />

<EditText
android:id="@+id/et_info"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="130dp"
android:maxHeight="80dp"
android:textColor="#009688"
android:background="@drawable/white"/>


<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="400dp"
android:textSize="20dp"
android:text="提交建议"/>

<Button
android:id="@+id/btn_read"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="400dp"
android:textSize="20dp"
android:text="查看我提交的建议"/>



</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">BookReading</string>
</resources>

0 comments on commit ca77bb6

Please sign in to comment.