Android] unable to add window token null is not for an application 이슈
안드로이드, listview, unable to add window token null is not for an application
아래와 같은 구조에서 AlertDialog.Builder를 생성했을시 unable to add window token null is not for an application 라는 에러로그가 찍혔다..
extends ListView
ListView 내의 Custom Adapter을 이용해서 생성한 하나의 View
View 내의 TextView
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder commentDlg = new AlertDialog.Builder(v.getRootView().getContext());
commentDlg.show()
}
}
혼자서 아무리 해결하려고 호출하는 ListActivity에 Context를 Static으로잡고 핸들러로 날리고 별 짓 다해봤는데 안됬다.
그래서 네이버를 검색 했는데 죄다 (Activity이름).this를 getApplicationContext()대신 쓰라고 하는것이다.
그래도 안된다....
그래서 구글링을 했는데 역시 스떽오버쁠로느님이 도와줬다.
http://stackoverflow.com/questions/6367771/displaying-alertdialog-inside-a-custom-listadapter-class
context를 얻을때 v.getRootView().getContext()를 사용하면(트릭이라고하는데?) 해결된다.