본문 바로가기

Study/Android

[android] R.id 의 값 동적으로 가져오기

String buttonID = "resolution_btn_" + idx ; 
        int resID = getResources().getIdentifier(buttonID, "id", getActivity().getPackageName()); 
        Button view = ((Button) mRootView.findViewById(resID)); 

실제 id 값들 
{R.id.resolution_btn_0, R.id.resolution_btn_1, R.id.resolution_btn_2, R.id.resolution_btn_3, R.id.resolution_btn_4, R.id.resolution_btn_5, R.id.resolution_btn_125}

 

 

 

출처: http://gonacon.blogspot.com/2016/05/android-rid.html