forked from hzuapps/android-labs-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
75 changes: 75 additions & 0 deletions
75
...p/src/main/java/edu/hzuapps/androidlabs/Soft1614080902440/Soft1614080902440Activity2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
soft1614080902440/app/src/main/res/layout/activity2_soft1614080902440.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |