2011-12-08 1 views
18
을 찾는 방법

이의 내가 내 활동에문자열에서보기 대신 R.id

<TextView android:id="@+id/titleText" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="@string/app_name" 
     android:textColor="#ffffffb0" android:padding="5px" /> 

내 응용 프로그램에서 고해상도의 레이아웃이 있다고 가정하자, 나는 텍스트 뷰이 명령

TextView tv = (TextView)findViewById(R.id.titleText); 
를 사용하여 얻을 나는 그 ID를 열거 할 필요가 있기 때문에

는하지만이

TextView tv = (TextView)findViewByString("R.id."+"titleText"); 

같은 다른 방법을 찾고 있어요. 여러분 중 누구도 제가 어떻게 그것에 대해 갈 수있는 힌트 또는 단서를 줄 수 있습니까? 감사합니다

답변

45

당신은 다음과 같이 사용할 수 있습니다

Resources res = getResources(); 
int id = res.getIdentifier("titleText", "id", getContext().getPackageName()); 

을 그리고 ID를 사용합니다.