이 주제에 대해 몇 가지 질문이 있지만 특정 문제를 발견하지 못했습니다.XML의 onClick 속성이 액티비티 클래스의 메소드에 연결됩니다.
내 layout.xml에는 버튼을 오른쪽으로 호출하는 태그 onClickListener
. 나는 활동에 구현하는 방법을
java.lang.IllegalStateException: Could not find a method handle_cancel(View) in the activity class com.matthieu.HelloWorldApplication for onClick handler on view class android.widget.Button with id 'button_cancel'
,하지만 ... 난 왜 이해가 안 Application
확장하는 클래스에서 찾고있다 : 나는 오류가 발생합니다. 보기와 그 모든 것은 활동에서만 설정됩니다.
사람이 여기에 필요 (NOT HelloWorldApplication 내 활동) 메소드의 선언 인 경우 :
public void handle_cancel(View v) {
// do something useful here
}
편집 (adamp 요청에서) ... 아마도 내 자신의 질문에 대답 :
여기에 그 레이아웃을 사용하는 코드의 일부입니다 ...
public class AddVocabularyActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.top); // that layout contains an empty LinearLayout id/main_content
}
private some_other_function() {
LinearLayout main_content = (LinearLayout) findViewById(R.id.main_content);
main_content.removeAllViews();
View.inflate(getApplicationContext(), R.layout.hello, main_content); // layout.hello is the one containing the button
}
// some other stuff
}
동안 복사 /이 코드를 붙여, 나는 추측하고 t 그 문제는 내 편집에서 언급 한 바와 같이 나는
레이아웃을 사용하는 곳에 코드를 게시 할 수 있습니까? – adamp