Study/Android
static method 안에서 LayoutInflater 사용하기
Answer Choi
2016. 8. 12. 11:21
반응형
alertDialog같은 팝업 UI등을 만들때 method나 class가 static으로 만들어야 하는 경우
LayoutInflater를 사용하여 특정 layout을 가져올려고 할 경우 에러가 발생합니다.
1 | LayoutInflater inflater = getLayoutInflater(); | cs |
static method에서는 사용할 수 없다고 오류를 발생시킵니다.
구글링해보니 context를 추가하면 된다고 되어있는데 안되네요.
결국 찾아낸 방법은 LayoutInflater.from(context)를 사용하면 됩니다.
1 | LayoutInflater inflater = LayoutInflater.from(mContext); | cs |
mContext는 static 타입의 Context입니다.
1 2 | static Context mContext; mContext=this; | cs |
위와 같이 미리 선언해 주면 됩니다.^^
반응형