上一篇我们简单的介绍了一下RoboGuice的使用(【一】注入框架RoboGuice使用:(A brief example of what RoboGuice does)),今天我们我看下View的注解的用法.

为了在Activity中使用View的注解。必须实现下面三个步骤:

①:自定义的Activity继承RoboActivity

②:设置内容视图 content View

③:使用 @InjectView来进行注解View控件

以下我们来具体看一下用法:

(一)首先创建一个继承与RoboActivity的Activity:

public class MyActivity extends RoboActivity {
...
}

然后加入一个布局到Activity中:

 // Override onCreate() and call setContentView()
public class MyActivity extends RoboActivity { @Override
protected void onCreate( Bundle savedState ) {
setContentView(R.layout.myactivity_layout);
}
}

我们在布局文件myactivity_layout.xml中定义了控件TextView该ID为text。如今就能够对该view控件进行注解而且能够不通过findViewByID进行初始化,直接使用了。

public class MyActivity extends RoboActivity {
@InjectView(R.id.text1) TextView textView; @Override
protected void onCreate( Bundle savedState ) {
setContentView(R.layout.myactivity_layout);
textView.setText("Hello!");
}
}

如今一个简单的View注解样例就完毕了。非常easy吧,是不是感觉省了非常多功夫了。

(二)contentview 注解

上面演示的是View注解,相同布局设置也能够通过注解来实现,例如以下:

@ContentView(R.layout.myactivity_layout)
public class MyActivity extends RoboActivity {
@InjectView(R.id.text1) TextView textView; @Override
protected void onCreate( Bundle savedState ) {
textView.setText("Hello!");
}
}

(三)当然除了上面的view控件,contentview注解。我们还能够注解不论什么类型的view,甚至还能够是自己定义View。

【二】注入框架RoboGuice使用:(Your First View Injection)的更多相关文章

  1. 【三】注入框架RoboGuice使用:(Your First Resource Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([二]注入框架RoboGuice使用:(Your First View Injection)),今天我们来看下资源文件的使用注解的方法: 为了在Ac ...

  2. 【五】注入框架RoboGuice使用:(Your First POJO Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([四]注入框架RoboGuice使用:(Your First System Service Injection)),今天我们来看下普通Java对象的 ...

  3. 【四】注入框架RoboGuice使用:(Your First System Service Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...

  4. 【六】注入框架RoboGuice使用:(Singletons And ContextSingletons)

    上一篇我们简单的介绍了一下RoboGuice的使用([五]注入框架RoboGuice使用:(Your First POJO Injection)),今天我们来看下单例以及上下文单例(ContextSi ...

  5. 【十一年】注入框架RoboGuice采用:(Your First Injection into a Custom View class)

    上一篇我们简单的介绍了一下RoboGuice的使用([十]注入框架RoboGuice使用:(Your First Testcase)),今天我们来看下自己定义View的注入(Custom View). ...

  6. 【十二】注入框架RoboGuice使用:(Your First Injected ContentProvider)

    上一篇我们简单的介绍了一下RoboGuice的使用([十一]注入框架RoboGuice使用:(Your First Injection into a Custom View class)),今天我们来 ...

  7. 【八】注入框架RoboGuice使用:(Your First Injected Fragment)

        上一篇我们简单的介绍了一下RoboGuice的使用([七]注入框架RoboGuice使用:(Your First Custom Binding)),今天我们来看下fragment的注解     ...

  8. 【十】注入框架RoboGuice使用:(Your First Testcase)

    上一篇我们简单的介绍了一下RoboGuice的使用([九]注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)),今天 ...

  9. 【九】注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)

    上一篇我们简单的介绍了一下RoboGuice的使用([八]注入框架RoboGuice使用:(Your First Injected Fragment)),今天我们来看下服务(Service)和广播接受 ...

随机推荐

  1. docloud后台管理项目(开篇)

    最近朋友做app需要web做后台管理,所以花了一周时间做了这个项目. 废话不多说,开发环境是nginx+php5.3,使用thinkphp框架.是一个医疗器械数据统计的后台,业务功能很简单就是查看用户 ...

  2. Codeforces_761_E_(dfs)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. python bs4库

    Beautiful Soup parses anything you give it, and does the tree traversal stuff for you. BeautifulSoup ...

  4. [Algorithm] 10. Reverse Integer

    Description Given a 32-bit signed integer, reverse digits of an integer. Example Example 1: Input: 1 ...

  5. [USACO06JAN] 牛的舞会 The Cow Prom

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  6. [Luogu] P4366 [Code+#4]最短路

    题目背景 在北纬 91° ,有一个神奇的国度,叫做企鹅国.这里的企鹅也有自己发达的文明,称为企鹅文明.因为企鹅只有黑白两种颜色,所以他们的数学也是以二进制为基础发展的. 比如早在 1110100111 ...

  7. Python学习笔记(2)数值类型

    进制转换 int函数任意进制转换为10进制 第一个参数传入一个字符串,任意进制的,第二个参数传入对这个字符串的解释,解释他为几进制 hex oct bin转换进制为16 8 或者2进制 例题中石油87 ...

  8. springboot的jsp热部署

    使用springboot每次修改jsp都需要重新启动是不是很麻烦呢?以下是解决办法! yml格式 server: servlet: jsp: init-parameters: development: ...

  9. Diango REST framework 视图继承图

  10. Linux学习笔记(二) 文件管理

    了解 Linux 系统基本的文件管理命令可以帮助我们更好的使用 Linux 系统,以下介绍几个常用的文件管理命令 1.pwd pwd 是 Print Working Directory 的简写,用于显 ...