Android Development First Experience-criminalintent

Source: Internet
Author: User

This time we continue to improve the application of criminal intent, make its function more perfect.

First we add a dialog box for criminal intent, which can either draw the user's attention or receive input from the user. Useful for prompting important information or providing user choice.

1: Create dialogfragment and add DatePicker to Alterdialog

@Override

Public Dialog Oncreatedialog (Bundle savedinstancestate) {
View v = layoutinflater.from (getactivity ())
. Inflate (r.layout.dialog_date, NULL);


return new Alertdialog.builder (Getactivity ())
        . Setview (V)
. Settitle (R.string.date_picker_title)
. Setpositivebutton (Android. R.string.ok,null)
. Create ();

2: Show Dialogfragment 

private static final String dialog_date = "Dialogdate";
Mdatebutton.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Fragmentmanager manager = Getfragmentmanager ();
Datepickerfragment Dialog = Datepickerfragment
. newinstance (Mcrime.getdate ());
Dialog.settargetfragment (Crimefragment.this, request_date);
Dialog.show (manager, Dialog_date);
}
});

3: Response DatePicker dialog box

public void Onactivityresult (int requestcode, int resultcode, Intent data) {
if (resultcode! = ACTIVITY.RESULT_OK) {
Return
}

if (Requestcode = = request_date) {
Date date = (date) data
. Getserializableextra (Datepickerfragment.extra_date);
Mcrime.setdate (date);
Updatecrime ();
Updatedate ();
}

The second is the toolbar design. Toolbars can place menu options, provide app navigation, and help unify design styles and build brand image.

1: Response menu option

Need to be in crimelistfragment.

Implementing the Onoptionsitemselected (MenuItem) method

@Override
public boolean onoptionsitemselected (MenuItem item) {
Switch (Item.getitemid ()) {
Case R.id.new_crime:
Crime Crime = new Crime ();
Crimelab.get (Getactivity ()). Addcrime (crime);
UpdateUI ();
mcallbacks.oncrimeselected (crime);
return true;
Default
return super.onoptionsitemselected (item);
}
}

In the Crimelistfragment

Respond tothe Show subtitle menu item Click event

Case R.id.show_subtitle:
msubtitlevisible =!msubtitlevisible;
Getactivity (). Invalidateoptionsmenu ();
Updatesubtitle ();
return true;

Finally create the database

1: Create a comfortable database

Creating the Crimebasehelper Class

public class Crimebasehelper extends Sqliteopenhelper {
private static final int VERSION = 1;
private static final String database_name = "CRIMEBASE.DB";
Public Crimebasehelper (Context context) {
Super (context, database_name, NULL, VERSION);
}
@Override
public void OnCreate (Sqlitedatabase db) {
}
@Override
public void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {
}
}

2: Writing to the database

Using Contentvalues







Values }

3: Read Database

Call Query (...) Method Query Record

Private Crimecursorwrapper Querycrimes (String whereclause, string[] whereargs) {
cursor cursor = Mdatabase.query (
Crimetable.name,
NULL,//Columns-null selects all Columns
Whereclause,
Whereargs,
NULL,//GroupBy
NULL,//having
Null //By
);
return new Crimecursorwrapper (cursor);
}



       

Android Development First Experience-criminalintent

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.