2014-07-07 7 views
1

내가 TextViewsonClick와 속성의 수백을 사용하는에 CustomDialog가에 방법을 속성, 지금은 Activity class 이러한 onClick 메서드에 액세스 할 수 있습니다. 이 CustomDialogActivity 클래스에서 팽창으로 나는 onClick 메서드에 액세스하려는, 그래서 방법을 만들 때 그 onClick 안드로이드 : 비 활동 XML을 온 클릭을 액세스하는 방법 액티비티 클래스

public void playerEdit(View view) { 
     Toast.makeText(this,"hello",Toast.LENGTH_LONG).show(); 
} 

처럼 분명히 그것은

Could not find a method playeEdit(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.TextView with id 'p1' 

Exception 발생이 액세스 할 수없는 클래스에서 가져 오기를 시도했다는 것을 의미합니다.

내 질문은 Activity Class에 어떻게 액세스 할 수 있습니까?

어떻게 처리해야합니까? Exception? 미리 감사드립니다.

답변

0

아마도 XML 파일에 오타가있을 수 있습니다. 방법 이름 대신 "playerEdit"의 "playeEdit"입니다

+0

여기에 실수로 작성된 것은 xml과 클래스 모두에서 playerEdit입니다. –

0
내가 당신에 AlertDialog를 구성 할 때, 당신은 비슷한 방식으로 그것을하고 있다는 것을 믿는다

:

ContextThemeWrapper themedContext = new ContextThemeWrapper(getActivity(),android.R.style.Theme_Dialog); 
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); 

(게시 전체 코드 도움)

xml의 onClick 처리기가 내부에서 찾고있는 활동 (및 XML이 부 풀리는 곳)이 원래 활동이 아닌 테마 활동에 있기 때문에 예외가 발생합니다!

당신은 너무처럼 클릭 핸들러는 ContextThemeWrapper 클래스를 확장 빌더로 그것을 통과하고 구현해야합니다

public static class MyContextThemeWrapper extends ContextThemeWrapper 
{ 

    public MyContextThemeWrapper() { 
     super(); 
    } 

    public MyContextThemeWrapper(Context base, int themeres) { 
     super(base, themeres); 
    } 

    public void playerEdit(View view) 
    { 
     // Do stuff when clicked 
    } 

} 

그리고 언급 한 바와 같이, 당신과 같이 빌더에 클래스를 전달합니다

:

MyContextThemeWrapper themedContext = new MyContextThemeWrapper(getActivity(), android.R.style.Theme_Dialog); 
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); 

이것은 작동합니까 ... 테스트했습니다!