Implementation and serializable of the android pop-up window

Source: Internet
Author: 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 ("are you sure you want to exit? ")). 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 ();}

When using the software, you will often encounter clicking a button to bring up a window for us to select whether or not. Then, on Android, it becomes a dialog implementation instance. Today, I will write two examples for selecting a dialog.

Setmessage is the title of dialog, and setpostivebutton is one of the two buttons. It is defined as "yes" here, and the other one is the opposite, the onclick in the subsequent rewriting is very simple to select the corresponding button to post-process the event response, but it must be accumulated frequently. for Android beginners, It is accumulated step by step.

In addition, the objects that must be written to the writeobject in the objectoutputstream operation are serialized today. Otherwise, an exception is reported, that is, implements serializable can be used to define the object.

Private Static final long serialversionuid =-870520749171665437l; or Private Static final long serialversionuid = 1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.