Skip to content

Commit

Permalink
Merge pull request #1224 from hhyzz/master
Browse files Browse the repository at this point in the history
#5 第五次实验代码 #262
  • Loading branch information
zengsn authored Apr 5, 2019
2 parents db47b9f + c54fcb5 commit 68b07ba
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
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>
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;
}
}
}
}
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">My Application</string>
</resources>

0 comments on commit 68b07ba

Please sign in to comment.