-
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 #1228 from Walk-With-Wind/master
- Loading branch information
Showing
3 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
...714080902205/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902205/NewActivity.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,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: | ||
} | ||
} | ||
} | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
students/soft1714080902205/app/src/main/res/layout/activity_new.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,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> |