Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
# COMP5047 – Android Lab/Studio Sessions (Week 6): 
 
# Lab 2: GUI Design and Activity and Intent Programming in Android: 
Lab 2 will encompass teamwork, in which one party will create the property application’s search page GUI 
(searchpage.xml), while the other party codes up the missing backend parts of the application 
(PropertyApp.java, PropertyList.java, PropertyDetails.java). Both parties will need to work together to link 
the GUI up to the backend code (e.g. agreeing on the ViewGroup and View widget IDs). Each party will also 
need to have equal understanding of the whole completed implementation. 
 
Part 6: Design/code a GUI layout for your property application, based on Android’s XML format and using 
the Eclipse IDE. In particular, create: 
 searchpage.xml (TODO 01, approx. 100 lines of XML when formatted such that each attribute-value 
pair is on its own line): 1 x screen, similar in functionality to that shown in the lectures, that assists 
the user in selecting property search criteria. The GUI should include two radio buttons for the user 
to select between buying and renting a property, as well as a button for initiating the property 
search. 
 Note: The design of the searchpage.xml GUI is for each team to decide; it does not need to be the 
same as the interface shown in the lectures (though it must have the two radio buttons and search 
button).  See the following website for further examples of GUI layouts: 
o URL: http://developer.android.com/guide/tutorials/views/index.html 
o URL: http://developer.android.com/guide/topics/ui/index.html 
 
Part 7: Code the missing backend parts of the application to do with: connecting the XML GUI to the 
program code; initiating the GUI widgets; and defining and triggering Intents and the Extras that will need to 
be passed on to the called Activities. You will find the lecture notes and the following URL to the Android 
SDK Reference helpful, and there are further tips and details in each of the relevant Activity class files, as 
listed below: 
 URL: http://developer.android.com/reference/packages.html 
 PropertyApp.java (TODO 02, 03, & 04): 
o 02 (approx. 1 line of code): Link the PropertyApp Activity class to the above created 
searchpage.xml GUI. 
o 03 (approx. 3 lines of code): Create string arrays for holding the data to be displayed in the 
Spinner widgets that are defined in the above created searchpage.xml GUI. For e.g., one 
Spinner string array might be called PropertyType and might like to contain the values: 
“Apartment”, “House”, and “Land”. 
o 04A (approx. 40 lines of code): Initialise the Spinner widgets found in the searchpage.xml 
GUI (e.g. propertyTypeSpinner, stateSpinner, bedroomsSpinner, bathroomsSpinner, 
carSpacesSpinner). This will typically entail: 
 Retrieving the Spinner widgets from the searchpage.xml file, using the method: 
“findViewById”. 
 Setting a listener for each of the Spinners, using the method: 
“setOnItemSelectedListener”. Note that you are not required to handle user 
interaction with the Spinners, i.e. you do not need to modify the “onItemSelected” 
and “onNothingSelected” methods. 
 Creating an adapter for each of the Spinners, to link the data up to the Spinner View 
widget. 
 Defining the layout resource for the drop down view, using the method: 
“setDropDownViewResource”. 
 Linking the above created adapters to each of the Spinner widgets, using the 
“setAdapter” method. 
o 04B (approx. 25 lines of code): Initialise the button widget (e.g. searchBtn) found in the 
searchpage.xml GUI, and triggering an Intent to start the PropertyList Activity, passing to it 
also whether the user is requesting “buy” or “rent” property data. This will typically entail: 
 Retrieving the button widget from the searchpage.xml file, using the method: 
“findViewById”. 
 Setting a listener for the button, using the method: “setOnClickListener”, and coding 
the associated “onClick” method. This method will determine whether the user has 
selected the ‘buy’ or ‘rent’ radio button and trigger an Intent based on this. This in 
itself will entail: 
 Retrieving the RadioGroup widget using the method findViewById, and then 
checking which radio button was selected using the method: 
“getCheckedRadioButtonId”. 
 Calling the “populatePropertyCatalog (boolean toRent)” method (note that 
this is a method specific to this application, not the Android SDK), and 
triggering an Intent by first creating it, then adding any required extras using 
the “putExtra” method, and then passing the Intent to the Android OS using 
the “startActivity” method. 
 PropertyList.java (TODO 05, 06, & 07): 
o 05 (approx. 1 line of code): Link the PropertyList Activity class to the propertylisting.xml GUI. 
This is similar to TODO 02. 
o 06 (approx. 3 lines of code): Retrieve the Extras Bundle that was passed to this Activity via 
the Intent call, and then retrieving the enclosed value for the 
“PropertyApp.EXTRA_TO_RENT” variable. 
o 07 (approx. 3 lines of code): Triggering another Intent, similar to TODO 04B, that loads the 
PropertyDetails class and adds PropertyApp.EXTRA_PROPERTY_ID as an Extra. 
 PropertyDetails.java (TODO 08, approx. 4 lines of code): Similar to TODO 06, retrieve the Intent’s 
Extras Bundle and the encompassed EXTRA_PROPERTY_ID and EXTRA_TO_RENT values. 
 
If you have successfully completed TODOs 01-08, you should now have a working COMP5047 PropertyApp 
demo. 
 
Part 8: Consolidation of what you have learnt, and dealing with Android Security Permissions: 
 Based on what you have learnt from the past six lab tasks in weeks 5 and 6, create from scratch an 
Android application consisting of the following files: 
o Two Activities, called: “MySampleActivity.java” and “ResultsActivity.java”. 
o Two XML GUIs, called: “main.xml” (this should be automatically created by Eclipse when you 
create your project) and “result.xml”. 
o “AndroidManifest.xml” (this should also be automatically created by Eclipse on creating the 
project). 
 The application should allow a user to fill in their name in the first activity, and then allow the user to 
press a button to initiate a second activity that provides a welcome message to that particular user, 
similar to that shown below. If you are unsure about something, see also the Android SDK Reference: 
o URL: http://developer.android.com/reference/packages.html 
  
 Now modify the application’s security permissions in the AndroidManifest.xml file to allow the 
application to access the Internet. See the following URL for information on security permission 
types: 
o URL: http://developer.android.com/reference/android/Manifest.permission.html 
 You can check an installed application’s security permissions by clicking the following from within 
the emulator: 
o Menu > Settings > Applications > Manage Applications > YOUR APP’S NAME.