Skip to content

Commit

Permalink
#5 #1510 第五次实验及报告
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleyChase committed May 31, 2018
1 parent b879497 commit d43cfd7
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 35 deletions.
Binary file added com1614080901245/51.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com1614080901245/52.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
package edu.hzuapps.androidlabs.com1614080901245;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.content.ContextWrapper;
import android.os.Bundle;

import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import android.widget.TextView;

import org.w3c.dom.Text;

public class com1614080901245Activity extends AppCompatActivity {
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1614080901245);
textView=(TextView)findViewById(R.id.textview_01);


textView.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent=new Intent(com1614080901245Activity.this,SecondActivity.class);

startActivity(intent);

}

});
}
}
import android.widget.EditText;
import android.widget.Button;

public class com1614080901245Activity extends AppCompatActivity {
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

@Override
public class com1614080901245Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1614080901245);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1614080901245);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}

}
((Button) findViewById(R.id.button_save)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = ((EditText) findViewById(R.id.editText)).getText().toString();
save(text);
}
});
}
public void save(String text){
FileOutputStream out=null;
BufferedWriter writer=null;
try{
out=openFileOutput("save", ContextWrapper.MODE_APPEND);
writer=new BufferedWriter(new OutputStreamWriter(out));
writer.write(text);
}catch (IOException e){
e.printStackTrace();
}finally {
try {
if(writer!=null){
writer.close();
}
}catch (IOException e){
e.printStackTrace();
}
}
}
}
12 changes: 12 additions & 0 deletions com1614080901245/main/res/layout/activity_com1614080901245.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@
android:drawableTop="@drawable/tongxun"
android:text=" 点击查看详情" />

<Button
android:id="@+id/button_save"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:text="保存"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.897"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
20 changes: 20 additions & 0 deletions com1614080901245/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 第五次实验报告
## Android存储编程
## 一、实验步骤
### 1.在Activity的xml文件里,添加一个保存文件名的按钮。
### 2.在Activity的java文件里,导入相应的java的io包。
### 3.再添加一个监听器,设置点击按钮后,利用save函数保存文件。
### 4.使用Git将文件提交到自己的库中。
### 1.在Activity的xml文件里,添加一个EditText,ID为editText。
### 2.在Activity的xml文件里,添加一个Buttun,ID为buttun_save。
### 3.在Activity的java文件里,导入相应的java的io包、ContextWrapper的包、buttun的包以及editText的包。
### 4.再添加一个buttun_save的监听器,设置点击按钮后,保存文件,文件来源于edittext。
### 5.添加save函数,写入保存文件的方法,将保存的文件命名为“ssave”。
### 6.运行程序,在Activity的edittext中输入one,用file explorer查看内部存储文件,可看到一个名为“save”的文件里面写着“one”。证明写入成功。
### 7.使用Git将文件提交到自己的库中。
## 二、实验结果截图
![image](https://github.com/CharleyChase/android-labs-2018/blob/master/com1614080901245/51.jpg)
![image](https://github.com/CharleyChase/android-labs-2018/blob/master/com1614080901245/52.PNG)
### 1.通过实验,我对安卓的存储编程有了一定的认识,并知道了如何去编写函数,将数据储存到文件。
### 2.其中也会碰到一些问题,于是参考了《Android第一行代码》这本书里的这方面的内容,理解后将其完成。
### 实验提交得有点晚,课程也差不多要结束了,不过回头想想,也学到了不少安卓知识。

0 comments on commit d43cfd7

Please sign in to comment.