Skip to content

Commit

Permalink
hzuapps#5 hzuapps#991 第五次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
HHuangF committed May 18, 2018
1 parent fa238e3 commit b898cd6
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
Binary file added soft1614080902440/Fifth/Soft1614080902440p1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902440/Fifth/Soft1614080902440p2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions soft1614080902440/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.androidlabs.soft1614080902440">

<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=".Soft1614080902440Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Soft1614080902440Activity1" />
<activity android:name=".Soft1614080902440Activity2"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package edu.androidlabs.soft1614080902440;

import android.app.Activity;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class Soft1614080902440Activity2 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2_soft1614080902440);
//获取UI对象
Button bt_write = (Button) findViewById(R.id.write);
Button bt_read = (Button) findViewById(R.id.read);
//对写入数据的按钮添加监听器
bt_write.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = ((EditText) findViewById(R.id.EditText_1)).getText().toString();
write(text);

}
});
//对读取数据的按钮添加监听器
bt_read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
read();

}
});
}
//写入数据
public void write(String text) {
FileOutputStream out = null;
BufferedWriter writer = null;
try {
out = openFileOutput("test.txt", ContextWrapper.MODE_APPEND);
writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write(text);
writer.flush();
out.flush();
writer.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(Soft1614080902440Activity2.this, "发布成功", Toast.LENGTH_SHORT).show();

}
//读取数据
public void read() {
String content = "";
try {
FileInputStream fis = openFileInput("test.txt");
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
content = new String(buffer);
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(Soft1614080902440Activity2.this, "发布内容为:" + content, Toast.LENGTH_SHORT).show();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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=".Soft1614080902440Activity2">

<EditText
android:id="@+id/EditText_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="@color/white"
android:hint="请输入要发布的内容..."
android:layout_marginTop="50dp"
android:text="" />
<Button
android:id="@+id/write"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发布信息"
android:layout_below="@id/EditText_1"
android:layout_marginTop="60dp"
android:layout_marginLeft="50dp" />
<Button
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查询信息"
android:layout_below="@id/EditText_1"
android:layout_marginTop="60dp"
android:layout_marginLeft="230dp" />


</RelativeLayout>

0 comments on commit b898cd6

Please sign in to comment.