Skip to content

Commit

Permalink
hzuapps#5 hzuapps#788 第5次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
wufchun committed Apr 8, 2019
1 parent 967dee7 commit dc717de
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 342 deletions.
5 changes: 2 additions & 3 deletions students/soft1714080902414/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1714080902414Activity2" />
<activity android:name=".Soft1714080902414Activity">
<activity android:name="edu.hzuapps.androidlabs.soft1714080902414.Soft1714080902414">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package edu.hzuapps.androidlabs.soft1714080902414;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Soft1714080902414 extends AppCompatActivity implements View.OnClickListener {
private Button button1;
private Button button2;
private EditText editText1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1=(Button) findViewById(R.id.bt1);
button2=(Button) findViewById(R.id.bt2);
editText1=(EditText) findViewById(R.id.et1);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
}

@Override
public void onClick(View view) {
switch (view.getId())
{
case R.id.bt1: String save=editText1.getText().toString().trim();
FileOutputStream fos;
try{
fos=openFileOutput("data.txt",MODE_PRIVATE);
fos.write(save.getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText( Soft1714080902414.this,"数据保存成功",Toast.LENGTH_SHORT).show();
break;
case R.id.bt2: String content="";
try {
FileInputStream fis=openFileInput("data.txt");
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
content=new String(buffer);
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(Soft1714080902414.this,"保存的数据为"+content,Toast.LENGTH_SHORT).show();
break;
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:background="@color/background"
>
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:text=""
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp"
android:text="点击按钮保存"
/>

<Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="100dp"
android:text="点击按钮查看" />

</LinearLayout>

</LinearLayout>
Loading

0 comments on commit dc717de

Please sign in to comment.