Vit*_*lio 5 java annotations android-annotations
我有一个抽象基类和两个子类;我在两个子类中有“相同”字段,用“不同”注释互相注释,我想将字段“向上”放入基类中,并在子类中添加注释。
有可能吗?(以下非工作伪代码)
abstract class Base {
Object field;
}
class C1 extends Base {
@Annotation1
super.field;
}
class C2 extends Base {
@Annotation2
super.field;
}
Run Code Online (Sandbox Code Playgroud)
假设您有以下布局:
fragment1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/commonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/viewInFragment1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
fragment2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/commonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/viewInFragment2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后你可以有这些Fragment课程:
@EFragment
public class BaseFragment extends Fragment {
@ViewById
TextView commonView;
@AfterViews
void setupViews() {
// do sg with commonView
}
}
@EFragment(R.layout.fragment1)
public class Fragment1 extends BaseFragment {
@ViewById
TextView viewInFragment1;
@Override
void setupViews() {
super.setupViews(); // common view is set up
// do sg with viewInFragment1
}
}
@EFragment(R.layout.fragment1)
public class Fragment2 extends BaseFragment {
@ViewById
TextView viewInFragment2;
@Override
void setupViews() {
super.setupViews(); // common view is set up
// do sg with viewInFragment2
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4355 次 |
| 最近记录: |