"The project training is a comprehensive exercise of Android fundamentals, in particular: the project will use some of the picture material, are randomly organized, will later upload a resource, including the item's basic function, also contains the picture material "
"Project title": Campus booking app Design comprehensive case "target"
The function of the main interface is indeed quite complex, so the surrounding content of the previous knowledge said. Now start talking about the code and layout file for this interface.
1, first look at the organizational structure of the project, otherwise it is not good to say their relationship:
(1) DB packets are all database-related
(2) All the eatall are in activity or fragment.
(3) Entity classes placed in entities
(4) The Util is the tool class
2, the main interface activity class is mainactivity, notice it inherits is Activitygroup, because still useless use fragment
/** * Hundred meters of the main interface, containing a tabhost, as the main navigation use * @author Administrator */public class Mainactivity extends Activitygroup {tabhost Tabh Ost GridView GV; String mainmenus[]={"Hundred meter food", "hundred meter Restaurant", "Recommended food", "My Favorites", "Health Tracker", "Gourmet Experience", "View Cuisines", "My Bill", "Advance booking", "System help", "hundred meters setting", "Registration Information"};int Mainmenuicons[]=new int[12]; list<map<string,object>> menudata; Data Eatapp app for main menu in//tab3, @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); tabHost= (tabHost ) Findviewbyid (r.id.maintabhost);//Initialize the Navigation interface Inittabhost (); app= (Eatapp) getapplication ();} private void Inittabhost () {tabhost.setup ();//When using the Tabhost control, the program must be added Tabhost.setup (Getlocalactivitymanager ()); Tabspec tab1=tabhost.newtabspec ("T1"); Tab1.setindicator ("Promotional discount", Getresources () getdrawable (r.drawable.logo_s)); I Ntent intent1=new Intent (mainactivity.this,discountfoodactivity.class); tab1.setcontent (INTENT1); Tabspec tab2=tabhost.newtabspec ("T2"); Tab2.setindicator ("My Bill", Getresources (). Getdrawable (r.drawable.logo_s)); Intent intent2=new Intent (mainactivity.this,accountactivity.class); tab2.setcontent (Intent2); Tabspec tab3=tabhost.newtabspec ("T3"); Tab3.setindicator ("Hundred meter Purchase", Getresources () getdrawable (r.drawable.logo_s)); Tab3.setcontent (R.id.main_tabmainface); Tabhost.addtab (TAB1); Tabhost.addtab (TAB2); Tabhost.addtab (TAB3);// Initialize TAB3 's main navigation page gv= (GridView) Findviewbyid (R.ID.MAIN_TABMAINFACE_GV); Initgridview ();} Initializes the primary navigation gridview in Tag3 private void Initgridview () {for (int i = 0; I <mainMenuIcons.length; i++) {mainmenuicons[i]= R.drawable.mainmenu_01+i;} Menudata=new arraylist<map<string,object>> (); for (int i = 0; i < mainmenus.length; i++) {map<string, Object>item =new hashmap<string,object> () item.put ("Menuimg", Mainmenuicons[i]); Item.put ("MenuTitle", Mainmenus[i]); Menudata.add (item);} Simpleadapter sa =new simpleadapter (this,menudata,r.layout.mainmenulist_item,new string[]{"menuImg", "MenuTitle"}, New Int[]{r.id.mainmenu_item_img,r.id.mainmenu_item_title}); Gv.setadapter (SA); Gv.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> arg0, View arg1, int arg2,long arg3) {}});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;} Menu click @overridepublic Boolean onoptionsitemselected (MenuItem item) {Intent intent=null; switch (Item.getitemid ()) { Case r.id.menu_shopcat://View Shopping cart menu Intent =new Intent (mainactivity.this,shopcartactivity.class); Break;case r.id.menu_ info://View personal Information log.i ("MSG", app.userinfo+ "login Information"), if (app.userinfo!=null) {Intent =new Intent (mainactivity.this, Userinfoactivity.class);} Else{new Logindialog (this);} Break;case r.id.menu_setting://System Setup Menu break;case r.id.menu_exit://System Launch menu MainActivity.this.finish (); break;} if (intent!=null) startactivity (intent); return super.onoptionsitemselected (item);} @Overrideprotected void Onresume () {super.onresume (); if (app.userinfo!=null) {settitle ("Hundred m purchase [" + App.userInfo.getUserName () + "]");}} /* When exiting, the data in the shopping cart */@Overrideprotected VOID OnDestroy () {Super.ondestroy (); Eatapp app= (Eatapp) getapplication (); App.orderItems.clear (); App.userinfo=null;finish ();}}Here are the functions of several methods, further explaining:
(1)
Tabhost Tabhost;
This is the bottom of the tab navigation to use.
(2) These are the Third tab of the content to use
GridView GV; String mainmenus[]={"Hundred meter food", "hundred meter Restaurant", "Recommended food", "My Favorites", "Health Tracker", "Gourmet Experience", "View Cuisines", "My Bill", "Advance booking", "System help", "hundred meters setting", "Registration Information"};int Mainmenuicons[]=new int[12]; List<map<string,object>> menudata; Data from the main menu in//TAB3
(3)
Eatapp app;
This is a custom application class designed to allow different activity to share a subset of the data "with the following description"
(4) The code involves a lot of other activity and classes, first explain
<span style= "Background-color:rgb (153, 255, 153); >discountfoodactivity.class : This place is an activity interface for discounted promotions </span>
<span style= "Background-color:rgb (153, 255, 153); >accountactivity.class : This is the billing information activity interface </span>
<span style= "Background-color:rgb (153, 255, 153); >shopcartactivity.class: Check Cart menu is clicked, go to Shopping cart activity interface </span>
<pre name= "code" class= "java" ><span style= "Background-color:rgb (153, 255, 153);" >userinfoactivity.class : User Information Activity Interface </span>
<span style= "Background-color:rgb (153, 255, 153); >new Logindialog (This) : There is a custom dialog interface to enable user login </span>
3. The layout file of the main interface is:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context =". Mainactivity "> <tabhost android:id=" @+id/maintabhost "android:layout_width=" Match_parent "a ndroid:layout_height= "Match_parent" > <linearlayout android:layout_width= "match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <framelayout Android:id= "@android: Id/tabcontent" android:layout_width= "Match_parent" Android: layout_height= "Match_parent" android:layout_weight= "1" ><linearlayout android:id= "@+id/main_tabMa Inface "android:layout_width=" match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <gridview android:id= "@+id/maIN_TABMAINFACE_GV "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:n Umcolumns= "4" android:padding= "8DP" android:gravity= "Center_horizontal" ></gridview></lin earlayout> </FrameLayout> <tabwidget android:id= "@android: Id/tabs" Android:layout_width= "Match_parent" android:layout_height= "wrap_content" > </TABW Idget> </LinearLayout> </TabHost></RelativeLayout>
Note put the tabwidget below to implement the label navigation in the next way.
4, the above used to a GridView, its elements are used in the layout file is:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" android:gravity= "Center_horizontal" > <imageview android:id= "@+id/ Mainmenu_item_img " android:layout_width=" 80DP " android:layout_height=" 80DP " android:scaletype=" Centercrop " /><textview android:id=" @+id/mainmenu_item_title " android:layout_width=" Wrap_ Content " android:layout_height=" wrap_content " android:textsize=" 16sp " android:layout_margintop= "5DP" android:text= "menu name" /></linearlayout>
The end, the next one, explains if the three sub-interfaces in the main interface are implemented.
Android Basics "Project Training" "4"