-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1224 from hhyzz/master
- Loading branch information
Showing
4 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
students/soft1714080902203/实验五/My Application/app/src/main/AndroidManifest.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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="edu.hzuapps.androidlabs.soft1714080902203"> | ||
|
||
<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=".Soft1714080902203Activity2"></activity> | ||
<activity android:name=".Soft1714080902203Activity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
/*new*/ | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
</manifest> |
66 changes: 66 additions & 0 deletions
66
...p/src/main/java/edu/hzuapps/androidlabs/soft1714080902203/Soft1714080902203Activity2.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,66 @@ | ||
package edu.hzuapps.androidlabs.soft1714080902203; | ||
import android.app.Activity; | ||
import android.content.Context; | ||
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.FileOutputStream; | ||
|
||
public class Soft1714080902203Activity2 extends Activity { | ||
private EditText et_info; | ||
private Button btn_save; | ||
private Button btn_read; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.soft_1714080902203_activity2); | ||
//获取布局文件中的控件 | ||
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(Soft1714080902203Activity2.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(Soft1714080902203Activity2.this,"您的爱豆简介已保存:"+content,Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
|
||
default: break; | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...1714080902203/实验五/My Application/app/src/main/res/layout/soft_1714080902203_activity2.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,55 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#FFFFE0" | ||
tools:context=".Soft1714080902203Activity2"> | ||
|
||
<TextView | ||
android:id="@+id/jianjie" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" | ||
android:layout_marginBottom="0.1dp" | ||
android:background="#FFD700" | ||
android:paddingLeft="20dp" | ||
android:text="输入你的爱豆简介:" | ||
android:textColor="#454545" | ||
android:textSize="25sp" /> | ||
|
||
<EditText | ||
android:id="@+id/et_info" | ||
android:layout_width="match_parent" | ||
android:layout_height="400dp" | ||
android:layout_below="@+id/jianjie" | ||
android:layout_alignParentLeft="true" | ||
android:layout_marginBottom="0.1dp" | ||
android:background="@drawable/border" | ||
android:ems="10" | ||
android:paddingLeft="20dp" | ||
android:textColor="#454545"> | ||
|
||
<requestFocus /> | ||
</EditText> | ||
|
||
<Button | ||
android:id="@+id/btn_read" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/et_info" | ||
android:layout_alignRight="@+id/et_info" | ||
android:background="#FFD700" | ||
android:text="查看" | ||
android:textColor="#454545" /> | ||
|
||
<Button | ||
android:id="@+id/btn_save" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/et_info" | ||
android:layout_alignParentLeft="@+id/et_info" | ||
android:background="#FFD700" | ||
android:text="保存" | ||
android:textColor="#454545" /> | ||
</RelativeLayout> |
3 changes: 3 additions & 0 deletions
3
students/soft1714080902203/实验五/My Application/app/src/main/res/values/strings.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,3 @@ | ||
<resources> | ||
<string name="app_name">My Application</string> | ||
</resources> |