CS 696 Mobile Phone Application DevelopmentFall Semester, 2009Doc 7 Attributes & DialogsSept 22, 2009Copyright ©, All rights reserved. 2009 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/opl.shtml) license defines the copyright on this document.API Demos2SourceandroidInstallation/platforms/android-1.6/samples/ApiDemoshttp://developer.android.com/guide/samples/index.htmlOn-lineDialog Demos34View AttributesView Attributes5<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:text= "Show Dialog" android:layout_height="wrap_content" android:id="@+id/show" android:layout_x="115dip" android:layout_width="wrap_content" android:layout_y="85dip" > </Button></AbsoluteLayout>Eclipse View Builder6Property Editor7View Attributes (Properties)8android:backgroundandroid:clickableandroid:contentDescriptionandroid:drawingCacheQualityandroid:duplicateParentStateandroid:fadingEdgeandroid:fadingEdgeLengthandroid:fitsSystemWindowsandroid:focusableandroid:focusableInTouchModeandroid:hapticFeedbackEnabledandroid:idandroid:isScrollContainerandroid:keepScreenOnandroid:longClickableandroid:minHeightandroid:minWidthandroid:nextFocusDownandroid:nextFocusLeftandroid:nextFocusRightandroid:nextFocusUpandroid:onClickandroid:paddingandroid:paddingBottomandroid:paddingLeftandroid:paddingRightandroid:paddingTopandroid:saveEnabledandroid:scrollXandroid:scrollYandroid:scrollbarAlwaysDrawHorizontalTrackandroid:scrollbarAlwaysDrawVerticalTrackandroid:scrollbarSizeandroid:scrollbarStyleandroid:scrollbarThumbHorizontalandroid:scrollbarThumbVerticalandroid:scrollbarTrackHorizontalandroid:scrollbarTrackVerticalandroid:scrollbarsandroid:soundEffectsEnabledandroid:tagandroid:visibilitySee http://developer.android.com/reference/android/R.styleable.html#ViewTextView Properties9android:autoLinkandroid:autoTextandroid:bufferTypeandroid:capitalizeandroid:cursorVisibleandroid:digitsandroid:drawableBottomandroid:drawableLeftandroid:drawablePaddingandroid:drawableRightandroid:drawableTopandroid:editableandroid:editorExtrasandroid:ellipsizeandroid:emsandroid:enabledandroid:freezesTextandroid:gravityandroid:heightandroid:hintandroid:imeActionIdandroid:imeActionLabelandroid:imeOptionsandroid:includeFontPaddingandroid:inputMethodandroid:inputTypeandroid:lineSpacingExtraandroid:lineSpacingMultiplierandroid:linesandroid:linksClickableandroid:marqueeRepeatLimitandroid:maxEmsandroid:maxHeightandroid:maxLengthandroid:maxLinesandroid:maxWidthandroid:minEmsandroid:minHeightandroid:minLinesandroid:minWidthandroid:numericandroid:passwordandroid:phoneNumberandroid:privateImeOptionsandroid:scrollHorizontallyandroid:selectAllOnFocusandroid:shadowColorandroid:shadowDxandroid:shadowDyandroid:shadowRadiusandroid:singleLineandroid:textandroid:textAppearanceandroid:textColorandroid:textColorHighlightandroid:textColorHintandroid:textColorLinkandroid:textScaleXandroid:textSizeandroid:textStyleandroid:typefaceandroid:widthhttp://developer.android.com/reference/android/R.styleable.html#TextViewTextView_numeric10If set, specifies that this TextView has a numeric input method. The default is false.Must be one or more (separated by '|') of the following constant values.ConstantValueDescriptioninteger0x01Input is numeric.signed0x003Input is numeric, with sign allowed.decimal0x05Input is numeric, with decimals allowed.TextView_digits11TextView has a numeric input method(This does not seem correct)Specific characters are the ones that it will acceptContainers - LinearLayout12Important Properties/ConceptsOrientationFill ModelWeightGravityPaddingFrom Chapter 8 Working with Containers of The Busy Coder's Guide to Android Development, Versio 2.1, Mark MurphyOrientation13android:orientationhorizontalview is a rowverticalview is a columnChange at runtimesetOrientation(LinearLayout.VERTICAL);setOrientation(LinearLayout.HORIZONTAL);Fill Model14subviews supplyandroid:layout_widthandroid:layout_heightSpecifyExact sizewrap_contentfill_parentWeight15android:layout_weightRelative weight of views to use in fill_parentA view of twice the weight take twice the spaceGravity16android:layout_gravitysetGravity()How do the subviews line upPadding17paddingLeft paddingRightpaddingToppaddingBottomandroid:paddingsetPadding()Demo1819DialogsTypes of Dialogs20AlertDialogCan have buttons and checkboxesProgressDialogDatePickerDialogTimePickerDialogCustom DialogsSee http://developer.android.com/guide/topics/ui/dialogs.htmlActivity.onCreateDialog(int)21static final int DIALOG_PAUSED_ID = 0;static final int DIALOG_GAMEOVER_ID = 1;protected Dialog onCreateDialog(int id) { Dialog dialog; switch(id) { case DIALOG_PAUSED_ID: // do the work to define the pause Dialog break; case DIALOG_GAMEOVER_ID: // do the work to define the game over Dialog break; default: dialog = null; } return dialog;}Create dialogs in onCreateDialogshowDialog(int)22To show a dialog in your activity call showDialog(int)which calls onCreateDialog the first timeshowDialog(DIALOG_PAUSED_ID);Creating an AlertDialog23 protected Dialog onCreateDialog(int id) { switch (id) { case SAMPLE_DIALOG_ID: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Hello").setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { DialogExample.this.finish(); Toast.makeText(getApplicationContext(), "Good Bye", Toast.LENGTH_SHORT).show(); } }); return builder.create(); default: return null; } }Class DialogExampleThree Buttons24PositiveNegativeNeutralCan have only one of eachButton types have no meaingPositive can do what every you wantThree Button Example25 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Do you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(getApplicationContext(), "Good Bye", Toast.LENGTH_SHORT).show(); DialogExample.this.finish(); }
View Full Document