[{"Id":1,"Name":"張三","Score":60},{"Id":2,"Name":"李四","Score":70},{"Id":3,"Name":"王小明","Score":80}]
2. 利用編輯器(例如eclipse)將擋案匯入到手機預設的sdcard路徑,下列程式碼為讀取預設sdcard路徑之檔案,等等會用到
String path=Environment.getExternalStorageDirectory().toString()+"/StudentList.txt";
3. 程式碼實作
1. StudentActivity.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
public class StudentActivity extends Activity {
private Button readBtn, nextBtn, prevBtn, saveBtn, clearoneBtn,
clearallBtn;
private EditText etID, etName, etScore;
private Switch wdSwitch;
private String path;
private ArrayList<Student> stuList;
private int rowCount;
private InputMethodManager inputMethodManager;
private Student student;
private static int INSERT_DATA = 0, REMOVE_DATA = 1, REMOVE_ALL_DATA = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student);
initObject();
}
public void initObject() {
path = Environment.getExternalStorageDirectory().toString()
+ "/StudentList.txt";
readBtn = (Button) this.findViewById(R.id.readBtn);
nextBtn = (Button) this.findViewById(R.id.nextBtn);
prevBtn = (Button) this.findViewById(R.id.preBtn);
etID = (EditText) this.findViewById(R.id.id_et);
etName = (EditText) this.findViewById(R.id.name_et);
etScore = (EditText) this.findViewById(R.id.score_et);
wdSwitch = (Switch) this.findViewById(R.id.write_swh);
clearoneBtn = (Button) this.findViewById(R.id.clearoneBtn);
clearallBtn = (Button) this.findViewById(R.id.clearallBtn);
saveBtn = (Button) this.findViewById(R.id.saveBtn);
inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
saveBtn.setEnabled(false);
readBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
readData();
}
});
nextBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
nextData();
}
});
prevBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
prevData();
}
});
saveBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
saveData();
}
});
clearoneBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (checkEditText()) {
clearOneData();
} else {
Toast.makeText(StudentActivity.this, "Please read data",
Toast.LENGTH_SHORT).show();
}
}
});
clearallBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (checkEditText()) {
clearAllData();
} else {
Toast.makeText(StudentActivity.this, "Please read data",
Toast.LENGTH_SHORT).show();
}
}
});
wdSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundBtn,
boolean isChecked) {
if (isChecked) {
closeButton();
openEditable();
} else {
openButton();
colseEditable(compoundBtn);
}
}
});
readJSONData();
}
public boolean checkEditText() {
return etID.getText().toString().equals("") ? false : true;
}
public void clearAllData() {
try {
JSONEncode(null, REMOVE_ALL_DATA);
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
Toast.makeText(this, "Remove all data", Toast.LENGTH_SHORT).show();
} catch (Exception io) {
Toast.makeText(this, io.getMessage(), Toast.LENGTH_SHORT).show();
}
}
public void clearOneData() {
try {
JSONEncode(null, REMOVE_DATA);
setDataText();
} catch (Exception io) {
Toast.makeText(this, io.getMessage(), Toast.LENGTH_SHORT).show();
}
}
public void setDataText() {
if (stuList.size() != 0) {
if (!(rowCount == stuList.size())) {
etID.setText(String.valueOf(stuList.get(rowCount)
.getStudentId()));
etName.setText(String.valueOf(stuList.get(rowCount)
.getStudentName()));
etScore.setText(String.valueOf(stuList.get(rowCount)
.getStudentScore()));
} else {
etID.setText(String.valueOf(stuList.get(0).getStudentId()));
etName.setText(String.valueOf(stuList.get(0).getStudentName()));
etScore.setText(String
.valueOf(stuList.get(0).getStudentScore()));
rowCount = 0;
}
Toast.makeText(this, "Remove data finish", Toast.LENGTH_SHORT)
.show();
} else {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
Toast.makeText(this, "Please insert data", Toast.LENGTH_SHORT)
.show();
}
}
public void readJSONData() {
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String data = br.readLine();
stuList = JSONDecode(data);
} catch (Exception e) {
}
}
public void saveData() {
try {
String id = etID.getText().toString();
String name = etName.getText().toString();
String score = etScore.getText().toString();
student = new Student(Integer.parseInt(id), name,
Double.parseDouble(score));
JSONEncode(student, INSERT_DATA);
Toast.makeText(this, "Save finish", Toast.LENGTH_SHORT).show();
} catch (NumberFormatException e) {
Toast.makeText(this, "Please input correct format",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private void JSONEncode(Student studentData, int data_type)
throws Exception {
JSONArray jsonArray = new JSONArray();
if (data_type == INSERT_DATA) {
stuList.add(studentData);
} else if (data_type == REMOVE_DATA) {
stuList.remove(rowCount);
} else if (data_type == REMOVE_ALL_DATA) {
int size = stuList.size();
for (int i = 0; i < size; i++) {
stuList.remove(0);
}
}
for (int i = 0; i < stuList.size(); i++) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Id", stuList.get(i).getStudentId());
jsonObject.put("Name", stuList.get(i).getStudentName());
jsonObject.put("Score", stuList.get(i).getStudentScore());
jsonArray.put(jsonObject);
}
FileWriter fw = new FileWriter(path);
fw.write(jsonArray.toString());
fw.close();
}
public void closeButton() {
readBtn.setEnabled(false);
nextBtn.setEnabled(false);
prevBtn.setEnabled(false);
clearoneBtn.setEnabled(false);
clearallBtn.setEnabled(false);
saveBtn.setEnabled(true);
}
public void openEditable() {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Input Data");
etName.setHint("Please Input Data");
etScore.setHint("Please Input Data");
etID.setFocusableInTouchMode(true);
etName.setFocusableInTouchMode(true);
etScore.setFocusableInTouchMode(true);
}
public void openButton() {
readBtn.setEnabled(true);
nextBtn.setEnabled(true);
prevBtn.setEnabled(true);
clearoneBtn.setEnabled(true);
clearallBtn.setEnabled(true);
saveBtn.setEnabled(false);
}
public void colseEditable(CompoundButton compBtn) {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
etID.setFocusable(false);
etName.setFocusable(false);
etScore.setFocusable(false);
inputMethodManager.hideSoftInputFromWindow(compBtn.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
public void readData() {
showData(0);
rowCount = 0;
}
public ArrayList<Student> JSONDecode(String JString) throws JSONException {
JSONArray jsonArray = new JSONArray(JString);
ArrayList<Student> jsonDecodeList = new ArrayList<Student>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("Name");
int id = jsonObject.getInt("Id");
double score = jsonObject.getDouble("Score");
student = new Student(id, name, score);
jsonDecodeList.add(student);
}
return jsonDecodeList;
}
public void showData(int index) {
if (stuList.size() > 0) {
Student student = stuList.get(index);
etID.setText("" + student.getStudentId());
etName.setText(student.getStudentName());
etScore.setText("" + student.getStudentScore());
} else {
Toast.makeText(this, "Please insert data", Toast.LENGTH_SHORT)
.show();
}
}
public void nextData() {
if (checkEditText()) {
if (stuList != null) {
rowCount++;
if (rowCount >= stuList.size()) {
rowCount = 0;
}
showData(rowCount);
}
} else {
Toast.makeText(this, "Please read data", Toast.LENGTH_SHORT).show();
}
}
public void prevData() {
if (checkEditText()) {
if (stuList != null) {
rowCount--;
if (rowCount < 0) {
rowCount = stuList.size() - 1;
}
showData(rowCount);
}
} else {
Toast.makeText(this, "Please read data", Toast.LENGTH_SHORT).show();
}
}
}
2. activity_student.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".StudentActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Id : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/id_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/score_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/readBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Read" />
<Button
android:id="@+id/preBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/readBtn"
android:text="Previous" />
<Button
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/preBtn"
android:text="Next" />
</RelativeLayout>
<Switch
android:id="@+id/write_swh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Writer Data" />
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Data" />
<Button
android:id="@+id/clearoneBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Data of one" />
<Button
android:id="@+id/clearallBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Data of all" />
</LinearLayout>
3. AndroidManifest.xml(重點程式碼)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
1. StudentActivity.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
public class StudentActivity extends Activity {
private Button readBtn, nextBtn, prevBtn, saveBtn, clearoneBtn,
clearallBtn;
private EditText etID, etName, etScore;
private Switch wdSwitch;
private String path;
private ArrayList<Student> stuList;
private int rowCount;
private InputMethodManager inputMethodManager;
private Student student;
private static int INSERT_DATA = 0, REMOVE_DATA = 1, REMOVE_ALL_DATA = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student);
initObject();
}
public void initObject() {
path = Environment.getExternalStorageDirectory().toString()
+ "/StudentList.txt";
readBtn = (Button) this.findViewById(R.id.readBtn);
nextBtn = (Button) this.findViewById(R.id.nextBtn);
prevBtn = (Button) this.findViewById(R.id.preBtn);
etID = (EditText) this.findViewById(R.id.id_et);
etName = (EditText) this.findViewById(R.id.name_et);
etScore = (EditText) this.findViewById(R.id.score_et);
wdSwitch = (Switch) this.findViewById(R.id.write_swh);
clearoneBtn = (Button) this.findViewById(R.id.clearoneBtn);
clearallBtn = (Button) this.findViewById(R.id.clearallBtn);
saveBtn = (Button) this.findViewById(R.id.saveBtn);
inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
saveBtn.setEnabled(false);
readBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
readData();
}
});
nextBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
nextData();
}
});
prevBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
prevData();
}
});
saveBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
saveData();
}
});
clearoneBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (checkEditText()) {
clearOneData();
} else {
Toast.makeText(StudentActivity.this, "Please read data",
Toast.LENGTH_SHORT).show();
}
}
});
clearallBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (checkEditText()) {
clearAllData();
} else {
Toast.makeText(StudentActivity.this, "Please read data",
Toast.LENGTH_SHORT).show();
}
}
});
wdSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundBtn,
boolean isChecked) {
if (isChecked) {
closeButton();
openEditable();
} else {
openButton();
colseEditable(compoundBtn);
}
}
});
readJSONData();
}
public boolean checkEditText() {
return etID.getText().toString().equals("") ? false : true;
}
public void clearAllData() {
try {
JSONEncode(null, REMOVE_ALL_DATA);
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
Toast.makeText(this, "Remove all data", Toast.LENGTH_SHORT).show();
} catch (Exception io) {
Toast.makeText(this, io.getMessage(), Toast.LENGTH_SHORT).show();
}
}
public void clearOneData() {
try {
JSONEncode(null, REMOVE_DATA);
setDataText();
} catch (Exception io) {
Toast.makeText(this, io.getMessage(), Toast.LENGTH_SHORT).show();
}
}
public void setDataText() {
if (stuList.size() != 0) {
if (!(rowCount == stuList.size())) {
etID.setText(String.valueOf(stuList.get(rowCount)
.getStudentId()));
etName.setText(String.valueOf(stuList.get(rowCount)
.getStudentName()));
etScore.setText(String.valueOf(stuList.get(rowCount)
.getStudentScore()));
} else {
etID.setText(String.valueOf(stuList.get(0).getStudentId()));
etName.setText(String.valueOf(stuList.get(0).getStudentName()));
etScore.setText(String
.valueOf(stuList.get(0).getStudentScore()));
rowCount = 0;
}
Toast.makeText(this, "Remove data finish", Toast.LENGTH_SHORT)
.show();
} else {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
Toast.makeText(this, "Please insert data", Toast.LENGTH_SHORT)
.show();
}
}
public void readJSONData() {
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String data = br.readLine();
stuList = JSONDecode(data);
} catch (Exception e) {
}
}
public void saveData() {
try {
String id = etID.getText().toString();
String name = etName.getText().toString();
String score = etScore.getText().toString();
student = new Student(Integer.parseInt(id), name,
Double.parseDouble(score));
JSONEncode(student, INSERT_DATA);
Toast.makeText(this, "Save finish", Toast.LENGTH_SHORT).show();
} catch (NumberFormatException e) {
Toast.makeText(this, "Please input correct format",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private void JSONEncode(Student studentData, int data_type)
throws Exception {
JSONArray jsonArray = new JSONArray();
if (data_type == INSERT_DATA) {
stuList.add(studentData);
} else if (data_type == REMOVE_DATA) {
stuList.remove(rowCount);
} else if (data_type == REMOVE_ALL_DATA) {
int size = stuList.size();
for (int i = 0; i < size; i++) {
stuList.remove(0);
}
}
for (int i = 0; i < stuList.size(); i++) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Id", stuList.get(i).getStudentId());
jsonObject.put("Name", stuList.get(i).getStudentName());
jsonObject.put("Score", stuList.get(i).getStudentScore());
jsonArray.put(jsonObject);
}
FileWriter fw = new FileWriter(path);
fw.write(jsonArray.toString());
fw.close();
}
public void closeButton() {
readBtn.setEnabled(false);
nextBtn.setEnabled(false);
prevBtn.setEnabled(false);
clearoneBtn.setEnabled(false);
clearallBtn.setEnabled(false);
saveBtn.setEnabled(true);
}
public void openEditable() {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Input Data");
etName.setHint("Please Input Data");
etScore.setHint("Please Input Data");
etID.setFocusableInTouchMode(true);
etName.setFocusableInTouchMode(true);
etScore.setFocusableInTouchMode(true);
}
public void openButton() {
readBtn.setEnabled(true);
nextBtn.setEnabled(true);
prevBtn.setEnabled(true);
clearoneBtn.setEnabled(true);
clearallBtn.setEnabled(true);
saveBtn.setEnabled(false);
}
public void colseEditable(CompoundButton compBtn) {
etID.setText("");
etName.setText("");
etScore.setText("");
etID.setHint("Please Read Data");
etName.setHint("Please Read Data");
etScore.setHint("Please Read Data");
etID.setFocusable(false);
etName.setFocusable(false);
etScore.setFocusable(false);
inputMethodManager.hideSoftInputFromWindow(compBtn.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
public void readData() {
showData(0);
rowCount = 0;
}
public ArrayList<Student> JSONDecode(String JString) throws JSONException {
JSONArray jsonArray = new JSONArray(JString);
ArrayList<Student> jsonDecodeList = new ArrayList<Student>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("Name");
int id = jsonObject.getInt("Id");
double score = jsonObject.getDouble("Score");
student = new Student(id, name, score);
jsonDecodeList.add(student);
}
return jsonDecodeList;
}
public void showData(int index) {
if (stuList.size() > 0) {
Student student = stuList.get(index);
etID.setText("" + student.getStudentId());
etName.setText(student.getStudentName());
etScore.setText("" + student.getStudentScore());
} else {
Toast.makeText(this, "Please insert data", Toast.LENGTH_SHORT)
.show();
}
}
public void nextData() {
if (checkEditText()) {
if (stuList != null) {
rowCount++;
if (rowCount >= stuList.size()) {
rowCount = 0;
}
showData(rowCount);
}
} else {
Toast.makeText(this, "Please read data", Toast.LENGTH_SHORT).show();
}
}
public void prevData() {
if (checkEditText()) {
if (stuList != null) {
rowCount--;
if (rowCount < 0) {
rowCount = stuList.size() - 1;
}
showData(rowCount);
}
} else {
Toast.makeText(this, "Please read data", Toast.LENGTH_SHORT).show();
}
}
}
2. activity_student.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".StudentActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Id : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/id_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score : "
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/score_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Please Read Data" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/readBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Read" />
<Button
android:id="@+id/preBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/readBtn"
android:text="Previous" />
<Button
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/preBtn"
android:text="Next" />
</RelativeLayout>
<Switch
android:id="@+id/write_swh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Writer Data" />
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Data" />
<Button
android:id="@+id/clearoneBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Data of one" />
<Button
android:id="@+id/clearallBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Data of all" />
</LinearLayout>
3. AndroidManifest.xml(重點程式碼)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
沒有留言:
張貼留言