Android 彈出二選一視窗的實現 及Serializable

來源:互聯網
上載者:User
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;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.