public void save() {@SuppressWarnings("rawtypes")File file = new File(SYSSETPATH);if (file.exists())file.delete();try {ObjectOutputStream objOutPutStream = new ObjectOutputStream(new FileOutputStream(file));objOutPutStream.writeObject(mSystemSet);objOutPutStream.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}
protected void onExit() {new AlertDialog.Builder(this).setTitle(getString(R.string.dlg_title)).setMessage(getString("確定要退出嗎?")).setPositiveButton(getString(R.string.yes),new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {setResult(Msg.SYSTEMEXIT);finish();}}).setNegativeButton(getString(R.string.no), null).show();}
在軟體使用過程中經常會遇到點擊某個按鈕後彈出讓我們選擇 是 或者 否 的視窗,這個再android上成為dialog 今天寫下二選一dialog的實現執行個體
setmessage是dialog的標題,setpostivebutton就是二選一的其中一個按鈕,這裡定義為“是”,相對應的另外一個就是否了,後面重寫的onclick為選擇相應的按鈕後處理事件的響應, 很簡單,但是要常常積累啊,初學android麼,就是一步一步的積累的。
另外今天在接觸 寫入操作 ObjectOutputStream中的writeobject 時 必須寫入的對象是序列化後的,不然會報異常,即在定義對象時 implements Serializable 借口並定義
private static final long serialVersionUID = -870520749171665437L;或者private static final long serialVersionUID = 1;