AndroidAnnotations是一个能够让你快速进行Android开发的开源框架,它能让你专注于真正重要的地方。使代码更加精简,使项目更加容易维护,它的目标就是“Fast Android Development.Easy maintainance”.
希望此篇能帮到大家,本系列教程目录:转载请链接并注明:转自 小树技术博客 .
AndroidAnnotations注解框架之介绍+配置(一): (飞机票)
@ViewGroup是AndroidAnnotations中比较特殊灵活的一个View注解,主要用于各种AA没涉及到的View的处理。例如Dialog,PopWindow,之类等等!(AA中没有@EDialog,但是使用@ViewGroup可以实现@EDialog的功能)
由于正好写项目用到了,所以顺便写一下教程。这里以写一个AA框架的Dialog为例子。
首先,将原有的dialog布局文件配置到@ViewGroup中,在ViewGroup中进行AA框架的功能应用,如@findByid等等。
@EViewGroup(R.layout.add_user_dialog)
public class AddUserDialog extends LinearLayout {
@ViewById(R.id.exit)
Button btn_exit;
public AddUserDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
照常创建Dialog对象,将之前的ViewGroup_对象作为视图设置到dialog中,最后显示dialog
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
YourDialogViewGroup viewGroup = new YourDialogViewGroup(mContext);
// We working on this, but for the moment you have to manually call onFinishInflate()
// when you programmatically instantiate custom components
viewGroup.onFinishInflate();
// You set the content view as your own custom component
dialog.setContentView(viewGroup);
// You still have to define the title here
dialog.setTitle(“Custom Dialog”);
注意
viewGroup.onFinishInflate();
必须完成视图的加载后才能进行Dialog的显示,否则会出现视图为空的问题。
由于时间关系就不详细写了,具体文档或解释见官网Wiki和Docs
地址:
Enhance-custom-views : 飞机票
F&Q:飞机票