336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
안드로이드 개발 시 리소스(xml, 이미지, 위젯 등)의 고유 ID를 가져오기 위해서 R클래스와 findViewById 를 주로 사용하는데 경우에 따라서 R 클래스를 쓰지 못하는 경우 다음과 같은 방법을 사용할 수 있다.

※ R 클래스와 findViewById를 사용하는 예제

mapView = (MapView)findViewById(R.id.map);


※ R 클래스 대신 findViewWithTag 를 사용하는 예제

currentNumber = (TextView) this.findViewWithTag("txt_currentnumber");

이때의 this는 context 객체였던거 같다. 이때 findViewWithTag 메소드를 사용하기 위해서는 resource xml 에 아래와 같이 태그를 설정해줘야 한다.

<TextView
            android:id="@+id/txt_currentnumber"
            android:textSize = "10dip"
            android:text="current" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:tag="txt_currentnumber"></TextView>


위의 예제는 위젯의 동적 ID를 가져오는 예제이고, resource xml 의 ID 값은 아래와 같이 가져올 수 있다.

※ R 클래스이용 시

int layoutResId = R.layout.page_navigation;


※ R 클래스이용하지 않고 동적 ID 값을 얻어올 경우


int layoutResId = context.getResources().getIdentifier("page_navigation", "layout", context.getPackageName());

속성값은 파일명(xml), 디렉토리명, 패키지명 이다.


참고로 SD 메모리의 경로를 동적으로 얻어오는 방법은 아래와 같다. (해보진 않았다;;)

Environment.getExternalStorageDirectory().getAbsolutePath()




블로그 이미지

By훈트

,