안드로이드 개발 질문/답변
(글 수 45,052)
ArrayAdapter를 생성하는 방법중에 createFromResouce 메소드를 이용하는 방법이 있더군요.
public static ArrayAdapter<CharSequence> createFromResource (Context context, int textArrayResId, int textViewResId)
Since: API Level 1
Creates a new ArrayAdapter from external resources. The content of the array is obtained through getTextArray(int)
.
Parameters
context | The application's environment. |
---|---|
textArrayResId | The identifier of the array to use as the data source. |
textViewResId | The identifier of the layout used to create views. |
Returns
- An ArrayAdapter
.
생성자를 써서 그냥 어댑터를 새로 만들어도 되는데
굳이 이러한 메소드가 있어야 하는 이유가 궁금합니다.
예제에서 위 메서드를 사용한 코드 인데요.
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.respondForDisplayItems, android.R.layout.simple_spinner_item);
생성자를 이용해서
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, getResources().getTextArray(R.array.respondForDisplayItems));
라고 만들어도 되지 않나요?