Skip to content

Commit

Permalink
hzuapps#5 第五次实验报告
Browse files Browse the repository at this point in the history
  • Loading branch information
Min4396 committed Jun 2, 2018
1 parent 5f86e86 commit bb67df0
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,76 @@
package soft1614080902434.androidlabs.hzuapps.edu.soft1614080902434;

import android.content.Context;
import android.support.annotation.RequiresPermission;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Second_Activity extends AppCompatActivity implements View.OnClickListener {
TextView t[] = new TextView[12];
EditText ed;
Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_);
this.RegisterEcent();
}
public void RegisterEcent(){
t[0]=(TextView) findViewById(R.id.n_0);
t[1]=(TextView) findViewById(R.id.n_1);
t[2]=(TextView) findViewById(R.id.n_2);
t[3]=(TextView) findViewById(R.id.n_3);
t[4]=(TextView) findViewById(R.id.n_4);
t[5]=(TextView) findViewById(R.id.n_5);
t[6]=(TextView) findViewById(R.id.n_6);
t[7]=(TextView) findViewById(R.id.n_7);
t[8]=(TextView) findViewById(R.id.n_8);
t[9]=(TextView) findViewById(R.id.n_9);
t[10]=(TextView) findViewById(R.id.n_10);
t[11]=(TextView) findViewById(R.id.n_11);
t[12]=(TextView) findViewById(R.id.n_12);
t[13]=(TextView) findViewById(R.id.n_13);
t[14]=(TextView) findViewById(R.id.n_14);
t[15]=(TextView) findViewById(R.id.n_15);
t[16]=(TextView) findViewById(R.id.n_16);
for(int i=0;i<17;i++){
t[i].setOnClickListener(this);
}

ed = (EditText)findViewById(R.id.edit_text);
send = (Button)findViewById(R.id.n_12);
send.setOnClickListener(this);
Log.d("dd","789");
}

@Override
public void onClick(View v) {

public void save(String str){
String data=str;
FileOutputStream out=null;
BufferedWriter writer=null;

try{
out =openFileOutput("wechat", Context.MODE_PRIVATE);
writer=new BufferedWriter(new OutputStreamWriter(out));
Log.d("dd","456");
writer.write(data);
} catch(IOException e){
e.printStackTrace();
} finally {
if (writer !=null){
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
public void onClick(View view){
if(view==send){
String str =ed.getText().toString();
this.save(str);
Log.d("dd","123");
}
// for(int i=0;i<17;i++){
// String str =t[i].getText().toString();
// this.save(str);
// String s=couting.getText().toString();
// ed.setText(s);
//
// }
// if(t[i]==view){
// String str =t[i].getText().toString();
// counting.append(str);
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
android:layout_x="269dp"
android:layout_y="262dp"
android:text="发送"
android:clickable="true"
tools:layout_editor_absoluteX="298dp"
tools:layout_editor_absoluteY="538dp" />

Expand Down
Binary file added soft1614080902434/5.1.png
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 soft1614080902434/5.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions soft1614080902434/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 第五次实验

## 1.实验目的

Android存储编程
## 2.实验步骤
1.打开实验4的工程项目,我要存储发送出去的数据。


2.用到两个关键字: FileOutputStream和BufferedWriter writer。

3.把按钮“发送”作为监听器,当你写上一些数据时,然后点击“发送”,系统此时就自动存储数据.

4.运行程序,然后从Android上面一排的View-Tool Windows-Device File Explorer,在这里找到soft1614080902434里面的File。

5.git push.并pull request.


## 3.实验结果
运行截图:



## 4.实验心得
这次实验还是比较难,因为我对存储文件很陌生,然后,我查看了一些课外书,找到了一些方法,一开始我运行之后,发现存储不了,找不到原因,然后就在别人的电脑运行,结果可以,然后我回到自己的电脑运行,结果可以了,这个,我学到了一点存储的方法。

0 comments on commit bb67df0

Please sign in to comment.