Android Annotations Use detailed

Source: Internet
Author: User
<span id="Label3"></p><p><p>In the use of the Java SSH framework, has been lamenting the annotation is really convenient ah, about the principle of annotations, you can refer to my other piece of the article Java annotation detailed. Recently have time to study the use of Android annotations, today to share with YOU.</p></p><p><p>The use of annotations in Android uses the open source framework androidannotations on Github. This open source framework should be the most widely used Android annotation framework, mainly due to the large number of annotation tags designed to meet most of our daily development needs. Androidannotations Many of the methods that can be extracted into the annotated label for our use, I will give you a concrete demonstration.<br>ok, So let's see how we can use this stuff.</p></p><p><p><strong>The first step</strong></p></p><p><p>Download androidannotations<br>After downloading the files, we will see that there are two jar packages:<br></p></p><p><p><strong>Step Two</strong></p></p><p><p>Configure the Framework on Eclipse:<br>1. Create a new Android project, copy the Androidannotations-api-3.2.jar to the Libs folder, and create a new folder in the project called compile-lib, Copy the Androidannotations-3.2.jar file in.<br><br>2. Select the item, right-click, select properties, See Java Compiler on the left side of the new window, check annotation processin under Java Compiler, and select Enable Project on the right Specific Settings, allows special settings to be given to the Project.<br><br>3. Expand annotation processin, Select Factory Path, then click Enable Project specific Settings on the right, and finally click Add JARs to add the jar Package.<br></p></p><p><p>4. Select the jar package we just created in the new folder, click ok,<br></p></p><p><p>well, the configuration on our development environment is now COMPLETE.</p></p><p><p><strong>Step Three</strong></p></p><p><p>Test whether the configuration was successful<br>Enter @e on an activity to see what the hint Is:<br>If you see the @eactivity, then congratulations, the configuration is successful, if not seen, please check the above steps.<br></p></p><p><p></p></p><p><p><strong>Fourth Step</strong></p></p><p><p>well, then we'll see how to use the Androidannotations.<br><strong>Use of 1.Activity annotations</strong><br>To modify the activity configuration in the manifest file, we will add a _ after mainactivity:</p></p><pre class="prettyprint"><code class=" hljs xml"> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">activity</span><span class="hljs-attribute">android:name</span>=<span class="hljs-value">". Mainactivity_ "</span><span class="hljs-attribute">android:label</span>=<span class="hljs-value">" @string/app_name "</span> > </span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">intent-filter</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">action</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">"android.intent.action.MAIN"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">category</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">"android.intent.category.LAUNCHER"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">intent-filter</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">activity</span>></span></span></code></pre><p><p>As for why to change the mainactivity to mainactivity_, I will explain to you later. Then add annotations on the Mainactivity:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"><span class="hljs-annotation">@EActivity</span>(R.layout.activity_main)<span class="hljs-keyword">public</span><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Activity</span> {</span></code></pre></pre><p><p>Remove the OnCreate () method <code>setContentView(R.layout.activity_main);</code> ,</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"> <span class="hljs-annotation">@Override</span> <span class="hljs-keyword">protected</span><span class="hljs-keyword">void</span><span class="hljs-title">onCreate</span>(Bundle savedInstanceState) { <span class="hljs-keyword">super</span>.onCreate(savedInstanceState); }</code></pre></pre><p><p>For the sake of convenience, we will first add some controls to the main layout file:</p></p><pre class="prettyprint"><code class=" hljs applescript"><linearlayout xmlns:android=<span class="hljs-string"><span class="hljs-string">"http://schemas.android.com/apk/res/android"</span></span>xmlns:tools=<span class="hljs-string"><span class="hljs-string">"http://schemas.android.com/tools"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>Android:paddingbottom=<span class="hljs-string"><span class="hljs-string">"@dimen/activity_vertical_margin"</span></span>android:paddingleft=<span class="hljs-string"><span class="hljs-string">"@dimen/activity_horizontal_margin"</span></span>android:paddingright=<span class="hljs-string"><span class="hljs-string">"@dimen/activity_horizontal_margin"</span></span>android:paddingtop=<span class="hljs-string"><span class="hljs-string">"@dimen/activity_vertical_margin"</span></span>android:orientation=<span class="hljs-string"><span class="hljs-string">"vertical"</span></span>tools:context=<span class="hljs-string"><span class="hljs-string">"com.example.androidannotations.MainActivity"</span></span>> <textview android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/textview1"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"@string/hello_world"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button1"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"Button1"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button2"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"Button2"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button3"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"Button3"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button4"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"Button4"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button5"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"Go to Next Activity"</span></span>/> <button android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/button6"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"multithreaded events"</span></span>/> <textview android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/textview2"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"TextView"</span></span>/> <textview android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/textview3"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"TextView"</span></span>/> <textview android:<span class="hljs-property"><span class="hljs-property">ID</span></span>=<span class="hljs-string"><span class="hljs-string">"@+id/textview4"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:<span class="hljs-type"><span class="hljs-type">text</span></span>=<span class="hljs-string"><span class="hljs-string">"TextView"</span></span>/></linearlayout></code></pre><p><p>This time we run to see if the system does not set the layout of the situation without error:<br></p></p><p><p>No crashes, all the contents of the normal display, it is thus <code>@EActivity(R.layout.activity_main)</code> replaced <code>setContentView(R.layout.activity_main);</code> , This is more convenient to Use.<br>To introduce an activity-related annotation, we often need to re-customize the title bar during activity use, so we need to hide the System's default title bar, then how to do this:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"><span class="hljs-annotation">@WindowFeature</span>({ Window.FEATURE_NO_TITLE , Window.FEATURE_INDETERMINATE_PROGRESS})<span class="hljs-annotation">@EActivity</span>(R.layout.activity_main)<span class="hljs-keyword">public</span><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Activity</span> {</span></code></pre></pre><p><p>:</p></p><p><p><br>The title bar has been successfully hidden, and is more convenient than the other way we hide the Title.</p></p><p><p><strong>2. Instantiating control annotations</strong></p></p><p><p>Instantiation control Annotations is another very useful annotation in androidannotations, but also solves the most boring work in our development process, under normal circumstances, we instantiate a control to use findviewbyid, get the control and then strong to the type we need, the code is large , and boring, then see what androidannotations bring us surprise?</p></p><p><p>There are four TextView on our main layout file, and I use the following three ways to instantiate it:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs css"> <span class="hljs-at_rule">@<span class="hljs-keyword">ViewById(R.id.textView1)</span> TextView tv1</span>; <span class="hljs-at_rule">@<span class="hljs-keyword">ViewById</span> TextView textView2</span>; <span class="hljs-at_rule">@<span class="hljs-keyword">ViewsById({R.id.textView3,R.id.textView4})</span> List<TextView> list</span>;</code></pre></pre><p><p>The First: <code>@ViewById(R.id.textView1)</code> This is a very standard way of writing. After declaring a control, and then using the @viewbyid annotation, the ID of the control is described in the note, which is equivalent to a line of code:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm">TextView tv1 = (TextView) this<span class="hljs-preprocessor">.findViewById</span>(R<span class="hljs-preprocessor">.id</span><span class="hljs-preprocessor">.textView</span>1)<span class="hljs-comment">;</span></code></pre></pre><p><p>The second: I did not specify the ID of the annotation tag to use, then how is it instantiated? Without specifying, Androidannotations uses the control name as the id, and my second control name is textView2, which is the same as the layout ID in the xml, so you can not specify the ID in the Annotations.<br>Third: If you want to declare multiple controls, you can put the controls into a list collection and then indicate multiple IDs in the Annotations.</p></p><p><p>After the control is instantiated, you can assign a value to the control immediately following It:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"> <span class="hljs-annotation">@AfterViews</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">initTextView</span>(){ tv1.setText(<span class="hljs-string">"hello world!"</span>); textView2.setText(<span class="hljs-string">"hello android annotations!"</span>); <span class="hljs-keyword">for</span>(TextView tv:list){ tv.setText(<span class="hljs-string">"hello lenve!"</span>); } }</code></pre></pre><p><p>This method executes after the instance finishes the Control.</p></p><p><p><strong>3. Event Annotations</strong><br>Most of the event androidannotations we have developed has provided us with annotations:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs ruby"> <span class="hljs-variable">@TextChange</span> <span class="hljs-variable">@AfterTextChange</span> <span class="hljs-variable">@BeforeTextChange</span> <span class="hljs-variable">@EditorAction</span> <span class="hljs-variable">@FocusChange</span> <span class="hljs-variable">@CheckedChange</span> <span class="hljs-variable">@Touch</span> <span class="hljs-variable">@Click</span> <span class="hljs-variable">@LongClick</span> <span class="hljs-variable">@ItemClick</span> <span class="hljs-variable">@ItemLongClick</span> <span class="hljs-variable">@ItemSelect</span> <span class="hljs-variable">@OptionsItem</span> <span class="hljs-variable">@SeekBarProgressChange</span> <span class="hljs-variable">@SeekBarTouchStart</span> <span class="hljs-variable">@SeekBarTouchStop</span></code></pre></pre><p><p>I am here to pick a simple, but also the most commonly used to say, is a point:</p></p><pre class="prettyprint"><code class=" hljs avrasm">@Click ({R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>1,r<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>2,r<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>3}) public void Btn_click (View v) {switch (v<span class="hljs-preprocessor"><span class="hljs-preprocessor">. GetId</span></span>()) {case R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>1:toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Maketext</span></span>(this,<span class="hljs-string"><span class="hljs-string">"btn1"</span></span>, Toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. LENGTH</span></span>_long)<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Show</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> break</span><span class="hljs-comment"><span class="hljs-comment">;</span></span>Case R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>2:toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Maketext</span></span>(this,<span class="hljs-string"><span class="hljs-string">"btn2"</span></span>, Toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. LENGTH</span></span>_long)<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Show</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> break</span><span class="hljs-comment"><span class="hljs-comment">;</span></span>Case R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>3:toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Maketext</span></span>(this,<span class="hljs-string"><span class="hljs-string">"btn3"</span></span>, Toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. LENGTH</span></span>_long)<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Show</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> break</span><span class="hljs-comment"><span class="hljs-comment">;</span></span>}} @Click (R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ID</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Button</span></span>4) public void Btn4_click () {Toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Maketext</span></span>(this,<span class="hljs-string"><span class="hljs-string">"btn4"</span></span>, Toast<span class="hljs-preprocessor"><span class="hljs-preprocessor">. LENGTH</span></span>_long)<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Show</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span>}</code></pre><p><p>Add a @click annotation on top of the method, indicate which Control's click event is in the note, and if it is a click event for multiple events, specify multiple IDs and use methods in the method <code>v.getId()</code> to differentiate Them. If you only set a click event for a control, look at the Button4 Example.</p></p><p><p>The annotation of the event is actually relatively simple, I will not say more, we are interested to view the official Documents.</p></p><p><p><strong>4. Threading Annotations</strong></p></p><p><p>This is probably the most exciting one of the Annotations. Here are the main two notes to You:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs ruby"><span class="hljs-variable">@Background</span><span class="hljs-variable">@UiThread</span></code></pre></pre><p><p>There is no doubt that the @Background is to let the method run in the child thread, while @uithreaad is letting the method run in the UI Thread.<br>Let's implement a simple effect, and after clicking on a button, let a textview automatically update the Value.</p></p><pre class="prettyprint"><code class=" hljs java"> <span class="hljs-annotation"><span class="hljs-annotation">@Background</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Doinbackground</span></span>(){<span class="hljs-keyword"><span class="hljs-keyword">Try</span></span>{<span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>(<span class="hljs-keyword"><span class="hljs-keyword">int</span></span>i =<span class="hljs-number"><span class="hljs-number">0</span></span>; I <<span class="hljs-number"><span class="hljs-number"></span> -</span>; I++) {tvshownumber (i); Thread.Sleep (<span class="hljs-number"><span class="hljs-number"></span> +</span>); } }<span class="hljs-keyword"><span class="hljs-keyword">Catch</span></span>(interruptedexception E) {e.printstacktrace (); } }<span class="hljs-annotation"><span class="hljs-annotation">@UiThread</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Tvshownumber</span></span>(<span class="hljs-keyword"><span class="hljs-keyword">int</span></span>I) {list.get (<span class="hljs-number"><span class="hljs-number">1</span></span>). SetText (i+<span class="hljs-string"><span class="hljs-string">""</span></span>); }</code></pre><p><p>first, in the Doinbackground method, the Tvshownumber (i) is executed every 1 seconds, and this method, if run in the main thread, causes a ANR exception, so it must be run in a child thread, but there is no way in Android to update the UI thread in a child thread. So we're going to add the @uithread tag on the Tvshownumber method, indicating that the method is running in the UI Thread.<br>Look:<br></p></p><p><p>There is a total abandonment of the annoying message, Handler (there should be applause here).</p></p><p><p><strong>value annotation between 5.Activity</strong><br>The jump between activity often requires data transfer, which needs to be obtained through bundles in the new activity, and whether it is empty, very cumbersome, and see how androidannotations solves the Problem:<br>Create a new secondactivity, note to modify the manifest file, add _ after the File:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs xml"> <span class="hljs-tag"><<span class="hljs-title">activity</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">".SecondActivity_"</span> <span class="hljs-attribute">android:label</span>=<span class="hljs-value">"@string/title_activity_second"</span> ></span> <span class="hljs-tag"></<span class="hljs-title">activity</span>></span></code></pre></pre><p><p>Secondactivity receive the mainactivity came from two parameters, one is name, one is address, we first look at the code in Mainactivity:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"> <span class="hljs-annotation">@Click</span>(R.id.button5) <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">go2NextActivity</span>(){ <span class="hljs-comment">//这里要注意第二个Activity的写法</span> <span class="hljs-keyword">new</span> Intent(<span class="hljs-keyword">this</span>,SecondActivity_.class); intent.putExtra(<span class="hljs-string">"name"</span><span class="hljs-string">"张三"</span>); intent.putExtra(<span class="hljs-string">"address"</span><span class="hljs-string">"xi‘an"</span>); startActivity(intent); }</code></pre></pre><p><p>Get the values from the mainactivity in the Secondactivity:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs css"> <span class="hljs-at_rule">@<span class="hljs-keyword">Extra("name")</span> String username</span>; <span class="hljs-at_rule">@<span class="hljs-keyword">Extra</span> String address</span>;</code></pre></pre><p><p>As in the previous section, if the parameter name is the same, you do not need to specify the argument name in the Annotation. This will automatically get the value from the Mainactivity. If the value in the mainactivity is empty, the error will not be heard, and the system will automatically handle the Exception.</p></p><p><p><strong>6. Resource file Annotations</strong><br>Use of resource files we can also use annotations, for example, to add a string to the Strings.xml:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs vhdl"><<span class="hljs-typename">string</span> name=<span class="hljs-string">"welcome"</span>>hello China,Hello xi\<span class="hljs-attribute">‘an</span><span class="hljs-keyword">and</span> guangzhou</<span class="hljs-typename">string</span>></code></pre></pre><p><p>In the program we will refer to this value:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs css"><span class="hljs-at_rule">@<span class="hljs-keyword">StringRes(R.string.welcome)</span> String welcome</span>;</code></pre></pre><p><p>This welcome automatically gets the value Here. Note that the <code>@StringRes</code> imported package is <code>import org.androidannotations.annotations.res.StringRes;</code> not a package that comes with android, so don't be fooled.</p></p><p><p>:<br></p></p><p><p><strong>7 Reasons for adding _</strong><br>Finally solve a problem, is what to add _ in the manifest file, to answer this question please first select the item, right-click, cancel apt_generated the previous Point.<br><br>After the cancellation, we have one more folder in our Project:<br></p></p><p><p>The activity in the folder here is the activity we just created, just a little more underline, and we'll open up the activity to see:<br></p></p><p><p>We write the layout file through the annotations, and it is generated here for us, so that we finally compile with the file here, which is why the manifest file is Underlined.</p></p><p><p><strong></strong> precautions<br>In the end, we emphasize a note that the code that uses annotations must not be modified with protected by the private modifier, because androidannotations when using annotations to generate the real source code, if our stuff is modified by private, It cannot invoke these things, so it can only be modified with Protected.</p></p><p><p>For more on androidannotations you can refer to the official documentation</p></p><p><p>well, about the use of androidannotations to introduce to you here, have any questions please leave a message. This project source code DOWNLOAD.</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced. If there is a wrong place, I would appreciate it if I could criticize it.</p></p> <p><p>Android Annotation Usage details (graphic)</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.