日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > android-annotations使用入門

android-annotations使用入門

來源:程序員人生   發布時間:2014-12-15 08:39:41 閱讀次數:2549次

轉載請標明出處:http://write.blog.csdn.net/postedit/41577317

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

非常好用,更重要的是它對性能無影響!本文我們扼要的來看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>  
里面定義了兩個activity,注意名字后面都帶了1個下劃線。

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之類的了。

如何進行編譯運行呢(參考https://github.com/excilys/androidannotations/wiki/CustomizeAnnotationProcessing):
(1)如果是使用javac,需要傳遞-AandroidManifestFile=/path/to/AndroidManifest.xml這個參數,指明Manifest文件。
(2)如果是使用Eclipse,在項目上點擊右鍵->Properties->Java Compiler->Annotation Processing->Enable annotation processing,
然后在Factory Path中添加AndroidAnnotations的jar包。
(3)如果是使用maven,maven-compiler-plugin的3.1版本可以設置編譯參數。
[html] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. <plugin>  
  2.     <artifactId>maven-compiler-plugin</artifactId>  
  3.     <version>3.1</version>  
  4.     <configuration>  
  5.          生活不易,碼農辛苦
    如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
    程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲二区视频 | 成人aa| 婷婷欧美| 久久99国产精品久久99大师 | 国产精品久久久久久 | 黑人猛交| 麻豆视频免费在线播放 | 国产精品片一区二区三区 | 51ⅴ精品国产91久久久久久 | 免费福利片 | 精品视频网站在线观看 | 91视频免费在线观看 | 国产成人aaaa | 国产一二视频 | 丰满少妇高潮惨叫久久久久 | 成人91看片| 久久九九久精品国产 | 国产免费看| 国产一区在线播放 | 国产精品久久久久久一级毛片 | 久久久久国产精品免费免费搜索 | 免费av一区二区三区 | 亚洲一区二区三区精品视频 | 国产视频久久久久久久 | 久久精品1| 欧美日韩国产在线看 | 2024国产精品视频 | 欧美伊人精品成人久久综合97 | 久久精品视频91 | 国产日韩欧美一区 | 国产成人精品久久二区二区 | 亚洲第一区在线 | 欧美日韩国产中文 | 极品视频在线 | 国产一区二区福利 | 国产99久久精品一区二区永久免费 | 在线成人精品国产区免费 | 麻豆视频一区 | 特黄网站 | 久久噜| 免费成人一级片 |