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() {
@Override
public 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;