반응형
android, findViewById casting bolierplate removal. |
<boilerplate casting removal>
@SuppressWarnings("unchecked")
public final <E extends View> E findView (int id) {
return (E) findViewById(id);
}
<사용방법>
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = findView(R.id.textview);
Button button = findView(R.id.button);
ImageView image = findView(R.id.imageview);
myMethod( findView(R.id.imageview) ); //Will not compile
myMethod( (ImageView) findView(R.id.imageview) ); //Compiles
}
private static void myMethod ( ImageView img ) {
//Do nothing
}
반응형
'프로그래밍 놀이터 > 안드로이드, Java' 카테고리의 다른 글
[JNI] fatal error: queue: No such file or directory (0) | 2014.04.18 |
---|---|
[android] rooting 없이 db 내용 보기. ( open source library ) (2) | 2014.04.17 |
android 에서 gif 재생하기 - GifDrawable. ( Open Source LIbrary ) (0) | 2014.04.16 |
[JNI] bitmap handling source code frame. (2) | 2014.04.16 |
[android] support v4 에 추가된 SwipeRefreshLayout. (0) | 2014.04.15 |
댓글