public static final String PREFERENCE_NAME = "SaveToFile";
protected static final String FileName = "fileDemo.txt";
@SuppressWarnings("deprecation")
public static int MODE = Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
};
btnshowAll.setOnClickListener(showAllListener);
//清除显示
OnClickListener clearListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
display.setText("");
}
};
btnClear.setOnClickListener(clearListener);
//全部删除
OnClickListener delAllListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
adapter.deleteALL();
Toast.makeText(SimplePreferenceDemoActivity.this, "删除成功!", Toast.LENGTH_LONG).show();
Builder ad = new AlertDialog.Builder(SimplePreferenceDemoActivity.this).setTitle("提示").setMessage("是否删除本地文件中的数据?");
ad.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@SuppressLint("SdCardPath")
@Override
public void onClick(DialogInterface dialog, int which) {
String path = "/data/data/edu.hrbue.SimplePreferenceDemo/files/fileDemo.txt";
File file = new File(path);
file.delete();
}
});
ad.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
ad.create();
ad.show();
}
};
btnDelAll.setOnClickListener(delAllListener);
//ID查询
OnClickListener btnSearchListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(idInput.getText().toString()==""){
Toast.makeText(SimplePreferenceDemoActivity.this, "请输入需要查询的ID!", Toast.LENGTH_LONG).show();
}else{
int id = Integer.parseInt(idInput.getText().toString());
Student[] stu = adapter.queryOneData(id);
if(stu==null){Toast.makeText(SimplePreferenceDemoActivity.this, "数据库中没有该项!", Toast.LENGTH_LONG).show();}
else{
display.setText(stu[0].toString());
}
}
}
};
btnSearch.setOnClickListener(btnSearchListener);
//ID更新
OnClickListener btnUpdateListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = Integer.parseInt(idInput.getText().toString());
Student[] stu = adapter.queryOneData(id);
/*nameText.setText("");
//先置为空
classText.setText("");
numText.setText("");*/
stu[0].name = nameText.getText().toString();
stu[0].Class = classText.getText().toString();
stu[0].num = numText.getText().toString();
long ifsuccess = adapter.updateOneData(id, stu[0]);
if(ifsuccess==-1){
Toast.makeText(SimplePreferenceDemoActivity.this, "更新失败!", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(SimplePreferenceDemoActivity.this, "更新成功!", Toast.LENGTH_LONG).show();
}
}
};
btnUpdate.setOnClickListener(btnUpdateListener);
//ID删除
OnClickListener btnDelListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = Integer.parseInt(idInput.getText().toString());
long ifsuccess = adapter.deleteOneData(id);
if(ifsuccess==-1){Toast.makeText(SimplePreferenceDemoActivity.this, "删除失败!", Toast.LENGTH_LONG).show();}
else{Toast.makeText(SimplePreferenceDemoActivity.this, "删除成功!", Toast.LENGTH_LONG).show();}
}
};
btnDelete.setOnClickListener(btnDelListener);
}
@Override
public void onStart(){
super.onStart();
loadSharedPreferences();
}
@Override
public void onStop(){
super.onStop();
saveSharedPreferences();
}
private void loadSharedPreferences(){
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCE_NAME, MODE);
String name = sharedPreferences.getString("Name","zzg");
String Class = sharedPreferences.getString("Class", "软件152");
String num = sharedPreferences.getString("Num","2015012919");
public class DBAdapter { private static final String DB_NAME = "student.db"; private static final String DB_TABEL = "studentInfo"; private static final int DB_VERTION = 1;
public static final String KEY_ID = "_id"; public static final String KEY_NAME = "name"; public static final String KEY_CLASS = "Class"; public static final String KEY_NUM = "num";
private SQLiteDatabase db; private final Context context; private DBOpenHelper dbOpenHelper;
/** 静态Helper类,用于建立、更新和打开数据库*/ private static class DBOpenHelper extends SQLiteOpenHelper{
public DBOpenHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub
} private static final String DB_CREATE = "create table "+DB_TABEL+"("+KEY_ID+" integer primary key autoincrement, "+KEY_NAME+" text not null, "+KEY_CLASS+" text not null, "+KEY_NUM+" text not null);"; @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(DB_CREATE); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS "+DB_TABEL); onCreate(db); //只是删除表,并没有复制数据 }}; public DBAdapter(Context _context){ context = _context; } public void close(){ if(db!=null){ db.close(); db=null; } } public void open(){ dbOpenHelper = new DBOpenHelper(context,DB_NAME,null,DB_VERTION); try{ db = dbOpenHelper.getWritableDatabase(); }catch(SQLiteException e){ db = dbOpenHelper.getReadableDatabase(); } } public long insert(Student student){//增 ContentValues newValue = new ContentValues(); newValue.put(KEY_NAME,student.name); newValue.put(KEY_CLASS,student.Class); newValue.put(KEY_NUM,student.num); return db.insert(DB_TABEL, null, newValue); } public long deleteOneData(long id){//删 return db.delete(DB_TABEL,KEY_ID+"="+id ,null); } public long deleteALL(){ return db.delete(DB_TABEL,null,null); } public long updateOneData(long id,Student student){//改 ContentValues updateValue = new ContentValues(); updateValue.put(KEY_NAME, student.name); updateValue.put(KEY_CLASS, student.Class); updateValue.put(KEY_NUM,student.num); return db.update(DB_TABEL, updateValue, KEY_ID+"="+id, null); } private Student[] ConvertToStudent(Cursor results) { // TODO Auto-generated method stub int resultCounts = results.getCount(); if(resultCounts==0||!results.moveToFirst()){return null;} Student[] students = new Student[resultCounts]; for(int i=0;istudents[i] = new Student(); students[i].ID = results.getInt(0); students[i].name = results.getString(results.getColumnIndex(KEY_NAME)); students[i].Class = results.getString(results.getColumnIndex(KEY_CLASS)); students[i].num = results.getString(results.getColumnIndex(KEY_NUM)); results.moveToNext(); } return students; } public Student[] queryOneData(long id){//查 Cursor results = db.query(DB_TABEL,new String[]{KEY_ID,KEY_NAME,KEY_CLASS,KEY_NUM},KEY_ID+"="+id,null,null,null,null);//7个参数 return ConvertToStudent(results); } public Student[] queryAll(){ Cursor results = db.query(DB_TABEL,new String[]{KEY_ID,KEY_NAME,KEY_CLASS,KEY_NUM},null,null,null,null,null); return ConvertToStudent(results); }
}
Student类:
package edu.hrbeu.SimplePreferenceDemo;
public class Student { public int ID=-1; public String name; public String Class; public String num;
@Override public String toString(){ String result=""; result += "ID:"+this.ID+"\n"; result += "Ãû×Ö:"+this.name+"\n"; result += "°à¼¶:"+this.Class+"\n"; result += "ѧºÅ:"+this.num+"\n"; return result; }
1 svn回退版本
1)在window中选择log,根据想要回退的内容,选择revert this version或revert chanages from this version
两者的区别:
revert this version:表示回退到当前版本(该版本后的版本全部作废)
revert chanages from this versio
<!--javascript取当月最后一天-->
<script language=javascript>
var current = new Date();
var year = current.getYear();
var month = current.getMonth();
showMonthLastDay(year, mont
public class MyStack {
private long[] arr;
private int top;
public MyStack() {
arr = new long[10];
top = -1;
}
public MyStack(int maxsize) {
arr = new long[maxsize];
top
Binary search needs an ordered array so that it can use array indexing to dramatically reduce the number of compares required for each search, using the classic and venerable binary search algori