あり、このテーマについてのかなりの数の質問がありますが、私が持っている特定の問題を持ついずれかを見つけることができませんでした...私のlayout.xmlでonClick属性
、私が使用ボタンを右に呼び出すタグ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
}
コピー/このコードを貼り付けている間、私はトンを推測しています彼の問題は、私の編集で述べたように、私は
レイアウトを使用する場所にコードを投稿できますか? – adamp