-
Notifications
You must be signed in to change notification settings - Fork 334
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
1 parent
b879497
commit d43cfd7
Showing
5 changed files
with
105 additions
and
35 deletions.
There are no files selected for viewing
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.
108 changes: 73 additions & 35 deletions
108
...80901245/main/java/edu/hzuapps/androidlabs/com1614080901245/com1614080901245Activity.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,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(); | ||
} | ||
} | ||
} | ||
} |
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
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,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第一行代码》这本书里的这方面的内容,理解后将其完成。 | ||
### 实验提交得有点晚,课程也差不多要结束了,不过回头想想,也学到了不少安卓知识。 |