多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > android-annotations使用入門

android-annotations使用入門

來源:程序員人生   發(fā)布時(shí)間:2014-12-15 08:39:41 閱讀次數(shù):2540次

轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://write.blog.csdn.net/postedit/41577317

androidannotation是1個(gè)非常牛逼的框架(https://github.com/excilys/androidannotations/wiki),可以做到:依賴注入(Dependency Injection),簡化的線程模型(Simplified  threading model),事件綁定(Event binding),REST Client。

非常好用,更重要的是它對(duì)性能無影響!本文我們扼要的來看1下1些入門的東西。
1.從例子開始(參考https://github.com/excilys/androidannotations/wiki/FirstActivity):
AndroidManifest.xml
[html] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="utf⑻"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.example.hello"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.     <uses-sdk  
  7.         android:minSdkVersion="14"  
  8.         android:targetSdkVersion="18" />  
  9.     <application  
  10.         android:allowBackup="true"  
  11.         android:icon="@drawable/ic_launcher"  
  12.         android:label="@string/app_name">  
  13.         <activity  
  14.             android:name="com.example.hello.MainActivity_"  
  15.             android:label="@string/app_name" >  
  16.             <intent-filter>  
  17.                 <action android:name="android.intent.action.MAIN" />  
  18.                 <category android:name="android.intent.category.LAUNCHER" />  
  19.             </intent-filter>  
  20.         </activity>  
  21.         <activity android:name="com.example.hello.SecondActivity_" />  
  22.     </application>  
  23. </manifest>  
里面定義了兩個(gè)activity,注意名字后面都帶了1個(gè)下劃線。

2.MainActivity.java:注意這里的名字沒有下劃線
[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. @EActivity(R.layout.activity_main)  
  2. public class MainActivity extends Activity {  
  3.     @ViewById(R.id.myInput)  
  4.     EditText myInput;  
  5.     @ViewById(R.id.myTextView)  
  6.     TextView textView;  
  7.     @ViewById(R.id.myButton2)  
  8.     Button btn2;  
  9.     @StringRes(R.string.go_to_second)  
  10.     String btn2Txt;  
  11.     @AfterViews  
  12.     protected void afterViews(){  
  13.         btn2.setText(btn2Txt);  
  14.     }  
  15.     @Click  
  16.     void myButton() {  
  17.         String name = myInput.getText().toString();  
  18.         textView.setText("Hello " + name);  
  19.     }  
  20.     @Click  
  21.     void myButton2(){  
  22.         SecondActivity_.intent(this).start();  
  23.     }  
  24. }  
  25. activity_main.xml  
  26. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  27.     xmlns:tools="http://schemas.android.com/tools"  
  28.     android:layout_width="match_parent"  
  29.     android:layout_height="match_parent"  
  30.     android:orientation="vertical" >  
  31.     <EditText    
  32.         android:id="@+id/myInput"  
  33.         android:layout_width="fill_parent"   
  34.         android:layout_height="wrap_content"  />  
  35.     <Button    
  36.         android:id="@+id/myButton"  
  37.         android:layout_width="fill_parent"   
  38.         android:layout_height="wrap_content"   
  39.         android:text="Click me!" />          
  40.     <TextView    
  41.         android:id="@+id/myTextView"  
  42.         android:layout_width="fill_parent"   
  43.         android:layout_height="wrap_content" />      
  44.     <Button    
  45.         android:id="@+id/myButton2"  
  46.         android:layout_width="fill_parent"   
  47.         android:layout_height="wrap_content"   
  48.         android:text="@string/go_to_second"/>    
  49. </LinearLayout>  
SecondActivity的源碼就不貼了。

使用注入以后,代碼看上去變得很簡潔,再也沒有那1大堆findViewById之類的了。

如何進(jìn)行編譯運(yùn)行呢(參考https://github.com/excilys/androidannotations/wiki/CustomizeAnnotationProcessing):
(1)如果是使用javac,需要傳遞-AandroidManifestFile=/path/to/AndroidManifest.xml這個(gè)參數(shù),指明Manifest文件。
(2)如果是使用Eclipse,在項(xiàng)目上點(diǎn)擊右鍵->Properties->Java Compiler->Annotation Processing->Enable annotation processing,
然后在Factory Path中添加AndroidAnnotations的jar包。
(3)如果是使用maven,maven-compiler-plugin的3.1版本可以設(shè)置編譯參數(shù)。
[html] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. <plugin>  
  2.     <artifactId>maven-compiler-plugin</artifactId>  
  3.     <version>3.1</version>  
  4.     <configuration>  
  5.          生活不易,碼農(nóng)辛苦
    如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
    程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国内精品久久国产大陆 | 国产一区二区播放 | 日本在线色 | 69国产视频 | 日本午夜三级 | 中文字幕看片在线a免费 | 日本精高清区一 | free性欧美高清vide0s | 国产主播福利 | 国产精品综合一区二区 | 久久国产免费一区二区三区 | 黄色网址免费大全 | 国产乱辈通伦影片在线播放亚洲 | 成人欧美一区二区三区在线观看 | 91日本在线观看亚洲精品 | www.亚洲天堂.com | 亚洲网站www | 欧美黄色一级片视频 | 久久亚洲国产精品一区二区 | 亚洲午夜精品久久久久久成年 | 免费观看性行为的视频网站 | 殴美xxx| 精品一区二区三区四区在线 | 欧美多人| 国产美女视频爽爽爽 | 五月婷婷免费视频 | 国产又黄又爽又色的免费 | 毛色毛片免费看 | 亚洲国产系列一区二区三区 | 欧美18一19sex性瑜伽 | 国产xxxxxx久色视频在 | 成人国产一区二区三区 | 最新亚洲国产有精品 | 亚洲精品在线网址 | 在线爱爱| 国内精品久久久久影院亚洲 | 91精品国产一区二区三区四区 | 日本一区毛片免费观看 | 波多野结衣资源在线 | 欧美娇小www| 国产免费午夜a无码v视频 |