그래서 switch나 if문으로 매번
getString(R.string.fragment_0)
getString(R.string.fragment_1)
getString(R.string.fragment_2)
...
를 해야하나 싶어서,
뒤의 숫자만 바꿔서 가져오는 방법을 찾으려했다.
int resId = getResources().getIdentifier("key_name", "string", getPackageName());
key_name과 찾고자 하는 R 이하의 항목, 그리고 Package name으로 Resource Id를 가져올 수 있는 함수가 존재했다!
Reference : http://stackoverflow.com/questions/6265417/dynamically-querying-a-string-is-strings-xml-file
댓글 없음:
댓글 쓰기