Preface standuptimer, an open-source project on the Android platform during this period, is a simple Android Application designed by jwood to control the conference time, similar to the stopwatch countdown. Android reminder
There are three main methods for Android notification: Toast notification, status bar notification, and dialog notification. Many dialog notifications are used in standup timer. Especially when deleting an item, a confirmation dialog box is displayed. There are four types of dialog notification: alert dialog, progressdialog, datepickerdialog, and timepickerdialog. This article focuses on alert dialog.
Alert dialog is easy to create. We will create a warning dialog box with edittext view by following the steps and create a team that participates in the meeting in standup timer. Step 1: override the oncreatedialog method and create a dialog box with different IDs. @ Override
Protected Dialog oncreatedialog ( Int ID)
{
Switch (ID)
{
Case Create_team_dialog:
If (Createteamdialog = Null )
{
Alertdialog. Builder = New Alertdialog. Builder ( This );
Builder. settitle (R. String. add_team );
Builder. setview (gettextentryview ());
Builder. setcancelable ( True );
// Set the OK button and listen for its events
Builder. setpositivebutton (R. String. OK, addteambuttonlistener ());
// Set the deny button and listen for its events
Builder. setnegativebutton (R. String. Revert, cancellistener ());
Createteamdialog = Builder. Create ();
}
ReturnCreateteamdialog;
Default:
Logger. E ("Attempting to create an unkonwn dialog with an ID"+ID );
ReturnNull;
}
}
Alertdialog. Builder is used to create a specific warning dialog box.
Settitle () is the title of the Set dialog box. setview (View) is used to load the view for the dialog box. If necessary, an edittext is loaded here. Setcancelable (Boolean) sets whether the return key can be undone dialog box, usually true setpositivebutton () sets the text of the button when the button is pressed, and the event listener setnegativebutton () of the button () set the text and listener of the cancel button. If the dialog box does not require a special view control, you do not need to use setview (). You can use setmessage (MSG) to display the expected warning information. After setting builder attributes, you can create the alertdialog dialog box through builder. Create. The dialog box displayed in step 2 is very simple. Add showdialog (ID) to the action you need to bring up the reminder. The dialog box is encapsulated by ID. Private Void Displayaddteamdialog (){
Showdialog (create_team_dialog );
}
In the third step, write the button event in the dialog box, which is similar to the normal button event writing. Here, the button event is handled by adding a team operation. Private Onclicklistener addteambuttonlistener (){
ReturnNewDialoginterface. onclicklistener (){
PublicVoidOnclick (dialoginterface dialog,IntID ){
Edittext collectedtextview=(Edittext) gettextentryview (). findviewbyid (R. Id. collected_text );
String name=Collectedtextview. gettext (). tostring ();
Team. Create (name, teamlistactivity.This);
Teamlistadapter. Add (name );
}
};
}
The onclicklistener under dialoginterface is returned.
Private Onclicklistener cancellistener (){
ReturnNewDialoginterface. onclicklistener (){
@ Override
PublicVoidOnclick (dialoginterface dialog,IntWhich ){
Dialog. Cancel ();
}
};
}
Undo dialog box operation, withdrawal warning.
About setview Code The gettextentryview method is called in several places. This is a custom method that returns the view. Setview allows you to display the view you want and receive user input information. Synchronized Protected View gettextentryview (){
If (Txtentryview = Null ){
Layoutinflater Factory = Layoutinflater. From ( This );
Txtentryview = Factory. Inflate (R. layout. collect_text, Null );
}
Return Txtentryview;
}
Layoutinflater can convert layout XML in the res folder to view. You can also useGetlayoutinflater () orGetsystemservice (string)
Method To create layoutinflater
Layoutinflater Inflater=(Layoutinflater) Context. getsystemservice
Context. layout_inflater_service );
Inflate (INT resid, viewgroup root) to convert a pre-defined XML layout file to view <? XML version = "1.0" encoding = "UTF-8" ?>
edittext xmlns: android = "http://schemas.android.com/apk/res/android" Android: ID =" @ + ID/collected_text "
Android: layout_width =" fill_parent " Android: layout_height =" fill_parent "
Android: padding =" 5dp " />
series of indexes
Android open-source project-standuptimer learning notes index