With the mobile internet and Internet + gradually popular, more and more enterprises began to enter the mobile internet, want to share through the Internet, but mobile internet development costs are still very high, such as the development of the iphone audit mechanism is long, may not meet the rapid deployment of applications, and developers relatively few, And China Mobile development team, you can use ten are Android under the under, so, in order to quickly integrate the Internet + trend, choose a developer more, resource-rich, low threshold development platform is the wise choice, in all, I chose Android as the development language into the mobile platform, So, back then, Android was developed based on Java, so what's the difference between Android and Java development for Java developers? Will Java development be the development of Android? So wearing these questions, we come into the Android world ....
If you want to compare the differences between Android and Java, we have a few simple examples, we introduce their relationship through a simple application, today's headlines may be no strangers, to save me personally, I particularly like this software, I am not advertising this software, is really good, very practical, is also very suitable for us to do examples of learning people's excellent design, good start, the following is my simple effect, is to, let everyone understand what I want to do next?
See if it is very similar, the above navigation bar can be left and right sliding, the following list click will have a prompt effect, this is what we are today to distance description of the content, OK, start on the code.
The first code below is a running portal. Activity is the main page we often talk about.
Import Java.util.arraylist;import java.util.hashmap;import Java.util.list;import Java.util.map;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.widget.listview;import Android.widget.simpleadapter;import Android.widget.tabhost;public class Mainactivity extends Actionbaractivity {private String AAA = "CEASDASD";p rivate ListView ListView = Null;public String getaaa () {return AAA;} public void Setaaa (String aaa) {this.aaa = AAA;} Public ListView Getlistview () {return listview;} public void Setlistview (ListView listview) {listview = ListView;} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Inittabhost (); Initlistview ();} public void Inittabhost () {Tabhost tabhost = (tabhost) Findviewbyid (Android. R.id.tabhost); Tabhost.setup (); Tabhost.addtab (Tabhost.newtabspec ("Tab1"). Setindicator ("headline"). SetContent ( R.id.listview1)); TabhosT.addtab (Tabhost.newtabspec ("TaB2"). Setindicator ("recommended"). SetContent (R.ID.VIEW2)); Tabhost.addtab ( Tabhost.newtabspec ("Tab3"). Setindicator ("Shenyang"). SetContent (R.ID.VIEW3)); Tabhost.addtab (Tabhost.newtabspec ("TAB4") ). Setindicator ("society"). SetContent (R.ID.VIEW4)); Tabhost.addtab (Tabhost.newtabspec ("Tab5"). Setindicator ("Entertainment"). SetContent (R.ID.VIEW5)) Tabhost.addtab (Tabhost.newtabspec ("Tab6"). Setindicator ("Technology"). SetContent (R.ID.VIEW6));} public void Initlistview () {this. ListView = (ListView) Findviewbyid (R.id.listview1); Simpleadapter adapter = new Simpleadapter (this, GetData (), r.layout.simple_list, new string[] {"title"},new int[] {r.id. TextView1}); Listview.setadapter (adapter); Listview.setonitemclicklistener (New Listitemonclicklistenerimp (This));} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem item) {int id = item.getitemid (); if (id = = r.id.action_settings) { return true;} RetUrn super.onoptionsitemselected (item);} Private list<map<string, object>> GetData () {list<map<string, object>> List = new arraylist< Map<string, object>> (); map<string, object> map = new hashmap<string, object> (); Map.put ("title", "Motorola"); List.add (map); map = new Hashmap<string, object> (); Map.put ("title", "Nokia"); List.add (map); map = new hashmap<string, object> (); Map.put ("title", "Samsung"); List.add (map); map = new hashmap<string, object> (); Map.put ("title", "Samsung"); List.add (map); Map = new hashmap<string, object> (), Map.put ("title", "Samsung"), List.add (map), map = new hashmap<string, object> ( ); Map.put ("title", "Samsung"), List.add (map), map = new hashmap<string, object> (), Map.put ("title", "Samsung"); List.add (map ); map = new hashmap<string, object> (); Map.put ("title", "Samsung"); List.add (map); map = new hashmap<string, Object > (); Map.put ("title", "Samsung"), List.add (map), map = new hashmap<string, object> (), Map.put ("title", "Samsung"), list.Add (map); return list;}} The next piece of code is an event class that I wrote separately, for the readability of the code, and the structure of the code, and the next Java use method is combined.
Import Java.util.map;import android.app.alertdialog;import Android.app.dialog;import Android.view.View;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;public Class Listitemonclicklistenerimp implements Onitemclicklistener {private mainactivity Mainactivity;public Listitemonclicklistenerimp (mainactivity supermainactivity) {this.mainactivity = supermainactivity;} @SuppressWarnings ("unchecked") @Overridepublic void Onitemclick (adapterview<?> arg0, View arg1, int arg2, long ARG3) {map<string, object> map_obj= (map<string, object>) This.mainActivity.getListView (). Getitematposition (arg2);D ialog alertdialog = new Alertdialog.builder (this.mainactivity). Settitle ("Message"). Setmessage (Map_obj.get ("title"). ToString ()). Setcancelable (True). Create (); Alertdialog.show ();}}
OK, now let's talk about the results of the study, what have we learned? Look closely at two pieces of code, is not very familiar with, elegant Java code, object-oriented development, inheritance, the event has all, it is Java development,
But he is very different from Java EE and desktop applications, he was born to adapt to the mobile, so continue to look at the code, summarized as follows:
All objects in 1,android can be obtained by Findviewbyid (ID), but the custom control is not automatically implemented by Android, and the ID is obtained in the following way: Android.r.id. Object ID.
2, write the event class separately need to pass in the main activity to be passed through the construction method, so that can be eaten, the other main class method through set and get can be obtained, and common object-oriented development is basically consistent.
The above two is a summary of the code, the following code is the page layout file Description:
<framelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:id=" @+id/container "android:layout_width=" Match_parent "android:layout_height= "Match_parent" tools:ignore= "Mergerootframe" > <tabhost android:id= "@android: Id/tabhost" Android : layout_width= "match_parent" android:layout_height= "match_parent" > <linearlayout android:l Ayout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > To Achieve the tab too much of the left and right moving effect, need to use Horizontalscrollview to implement, we just need to add to the periphery of tabwidget. Summed up a lot, to write a lot, because the work, time is not a lot, today wrote here, tomorrow will continue to improve, every day is not simple to complete the task, but through the actual needs of the work to
Improve themselves, so to adhere to write a summary, will be summed up their experience to share to everyone, but also to their own backup, in case of a rainy day, and when you really write out, you really did a corresponding summary
You really progress, write bad, just get started, there is not the place also hope that cattle people more guidance.
Android Development vs. Java development