forked from hzuapps/android-labs-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
24 deletions.
There are no files selected for viewing
80 changes: 56 additions & 24 deletions
80
...4/2.app/2.app/src/main/java/edu/hzupps/androidlabs/soft1614080902434/Second_Activity.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 |
---|---|---|
@@ -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); | ||
// } | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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.实验心得 | ||
这次实验还是比较难,因为我对存储文件很陌生,然后,我查看了一些课外书,找到了一些方法,一开始我运行之后,发现存储不了,找不到原因,然后就在别人的电脑运行,结果可以,然后我回到自己的电脑运行,结果可以了,这个,我学到了一点存储的方法。 | ||
|