Skip to content

Commit

Permalink
Merge pull request #1228 from Walk-With-Wind/master
Browse files Browse the repository at this point in the history
#5 #342 提交实验五
  • Loading branch information
zengsn authored Apr 5, 2019
2 parents 68b07ba + 397ca77 commit 8d0d66f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
4 changes: 3 additions & 1 deletion students/soft1714080902205/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".Soft1714080902205Activity"></activity>
<activity android:name=".NewActivity"/>
<activity android:name=".Soft1714080902205Activity_bottom" />
<activity android:name=".Soft1714080902205Activity" android:label="创作工作室"></activity>
<activity android:name=".Soft1714080902205Activity_start">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.hzuapps.androidlabs.soft1714080902205;

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.FileOutputStream;

public class NewActivity extends AppCompatActivity {

private EditText book_name_et;
private Button btn_save;
private Button btn_look;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);

book_name_et=(EditText) findViewById(R.id.book_name_et);
btn_save=(Button) findViewById(R.id.btn_save);
btn_look=(Button) findViewById(R.id.btn_look);

btn_save.setOnClickListener(new ButtonListener());
btn_look.setOnClickListener(new ButtonListener());
}
private class ButtonListener implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_save:
String saveInfo=book_name_et.getText().toString().trim();
FileOutputStream mfos;
try {
mfos=openFileOutput("MyBook.txt",MODE_PRIVATE);
mfos.write(saveInfo.getBytes());
mfos.close();
}
catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(NewActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_look:
String content="";
try {
FileInputStream mfis = openFileInput("MyBook.txt");
byte[] buffer = new byte[mfis.available()];
mfis.read(buffer);
content = new String(buffer);
mfis.close();
}
catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(NewActivity.this,"你保存的书名是:"+content,Toast.LENGTH_SHORT).show();
break;
default:
}
}
}
}

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


<TextView
android:id="@+id/book_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="请输入新创作书籍的书名:" />

<EditText
android:id="@+id/book_name_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/book_name"
android:ems="20"
/>

<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/book_name_et"
android:text="保存"
android:textSize="20sp"
android:layout_centerInParent="true"
/>

<Button
android:id="@+id/btn_look"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_save"
android:text="查看"
android:textSize="20sp"
android:layout_centerInParent="true"
/>


</RelativeLayout>

0 comments on commit 8d0d66f

Please sign in to comment.